20 #define pr_fmt(fmt) "llcp: %s: " fmt, __func__
23 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <net/nfc/nfc.h>
48 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
54 static u16 llcp_tlv16(
u8 *tlv,
u8 type)
56 if (tlv[0] != type || tlv[1] != llcp_tlv_length[tlv[0]])
63 static u8 llcp_tlv_version(
u8 *tlv)
68 static u16 llcp_tlv_miux(
u8 *tlv)
73 static u16 llcp_tlv_wks(
u8 *tlv)
78 static u16 llcp_tlv_lto(
u8 *tlv)
83 static u8 llcp_tlv_opt(
u8 *tlv)
88 static u8 llcp_tlv_rw(
u8 *tlv)
102 length = llcp_tlv_length[
type];
103 if (length == 0 && value_length == 0)
105 else if (length == 0)
115 memcpy(tlv + 2, value, length);
121 u8 *tlv_array,
u16 tlv_array_len)
125 pr_debug(
"TLV array length %d\n", tlv_array_len);
130 while (offset < tlv_array_len) {
134 pr_debug(
"type 0x%x length %d\n", type, length);
153 pr_err(
"Invalid gt tlv value 0x%x\n", type);
157 offset += length + 2;
161 pr_debug(
"version 0x%x miu %d lto %d opt 0x%x wks 0x%x\n",
170 u8 *tlv_array,
u16 tlv_array_len)
174 pr_debug(
"TLV array length %d\n", tlv_array_len);
179 while (offset < tlv_array_len) {
183 pr_debug(
"type 0x%x length %d\n", type, length);
187 sock->
miu = llcp_tlv_miux(tlv) + 128;
190 sock->
rw = llcp_tlv_rw(tlv);
195 pr_err(
"Invalid gt tlv value 0x%x\n", type);
199 offset += length + 2;
203 pr_debug(
"sock %p rw %d miu %d\n", sock, sock->
rw, sock->
miu);
213 pr_debug(
"ptype 0x%x dsap 0x%x ssap 0x%x\n", ptype, dsap, ssap);
215 header[0] = (
u8)((dsap << 2) | (ptype >> 2));
216 header[1] = (
u8)((ptype << 6) |
ssap);
218 pr_debug(
"header 0x%x 0x%x\n", header[0], header[1]);
250 pr_err(
"Could not allocate PDU\n");
254 skb = llcp_add_header(skb, sock->
dsap, sock->
ssap, cmd);
325 u8 *service_name_tlv =
NULL, service_name_tlv_length;
326 u8 *miux_tlv =
NULL, miux_tlv_length;
327 u8 *rw_tlv =
NULL, rw_tlv_length,
rw;
342 &service_name_tlv_length);
343 size += service_name_tlv_length;
349 size += miux_tlv_length;
353 size += rw_tlv_length;
363 if (service_name_tlv !=
NULL)
364 skb = llcp_add_tlv(skb, service_name_tlv,
365 service_name_tlv_length);
367 skb = llcp_add_tlv(skb, miux_tlv, miux_tlv_length);
368 skb = llcp_add_tlv(skb, rw_tlv, rw_tlv_length);
375 pr_err(
"error %d\n", err);
377 kfree(service_name_tlv);
388 u8 *miux_tlv =
NULL, miux_tlv_length;
389 u8 *rw_tlv =
NULL, rw_tlv_length,
rw;
403 size += miux_tlv_length;
407 size += rw_tlv_length;
415 skb = llcp_add_tlv(skb, miux_tlv, miux_tlv_length);
416 skb = llcp_add_tlv(skb, rw_tlv, rw_tlv_length);
423 pr_err(
"error %d\n", err);
437 pr_debug(
"Sending DM reason 0x%x\n", reason);
455 skb = llcp_add_header(skb, dsap, ssap,
LLCP_PDU_DM);
488 struct sock *
sk = &sock->
sk;
490 size_t frag_len = 0, remaining_len;
491 u8 *msg_data, *msg_ptr;
493 pr_debug(
"Send I frame len %zd\n", len);
500 if (msg_data ==
NULL)
511 while (remaining_len > 0) {
513 frag_len =
min_t(
size_t, sock->
miu, remaining_len);
515 pr_debug(
"Fragment %zd bytes remaining %zd",
516 frag_len, remaining_len);
535 remaining_len -= frag_len;