0001
0002
0003
0004
0005
0006 enum llcp_state {
0007 LLCP_CONNECTED = 1,
0008 LLCP_CONNECTING,
0009 LLCP_CLOSED,
0010 LLCP_BOUND,
0011 LLCP_LISTEN,
0012 };
0013
0014 #define LLCP_DEFAULT_LTO 100
0015 #define LLCP_DEFAULT_RW 1
0016 #define LLCP_DEFAULT_MIU 128
0017
0018 #define LLCP_MAX_LTO 0xff
0019 #define LLCP_MAX_RW 15
0020 #define LLCP_MAX_MIUX 0x7ff
0021 #define LLCP_MAX_MIU (LLCP_MAX_MIUX + 128)
0022
0023 #define LLCP_WKS_NUM_SAP 16
0024 #define LLCP_SDP_NUM_SAP 16
0025 #define LLCP_LOCAL_NUM_SAP 32
0026 #define LLCP_LOCAL_SAP_OFFSET (LLCP_WKS_NUM_SAP + LLCP_SDP_NUM_SAP)
0027 #define LLCP_MAX_SAP (LLCP_WKS_NUM_SAP + LLCP_SDP_NUM_SAP + LLCP_LOCAL_NUM_SAP)
0028 #define LLCP_SDP_UNBOUND (LLCP_MAX_SAP + 1)
0029
0030 struct nfc_llcp_sock;
0031
0032 struct llcp_sock_list {
0033 struct hlist_head head;
0034 rwlock_t lock;
0035 };
0036
0037 struct nfc_llcp_sdp_tlv {
0038 u8 *tlv;
0039 u8 tlv_len;
0040
0041 char *uri;
0042 u8 tid;
0043 u8 sap;
0044
0045 unsigned long time;
0046
0047 struct hlist_node node;
0048 };
0049
0050 struct nfc_llcp_local {
0051 struct list_head list;
0052 struct nfc_dev *dev;
0053
0054 struct kref ref;
0055
0056 struct mutex sdp_lock;
0057
0058 struct timer_list link_timer;
0059 struct sk_buff_head tx_queue;
0060 struct work_struct tx_work;
0061 struct work_struct rx_work;
0062 struct sk_buff *rx_pending;
0063 struct work_struct timeout_work;
0064
0065 u32 target_idx;
0066 u8 rf_mode;
0067 u8 comm_mode;
0068 u8 lto;
0069 u8 rw;
0070 __be16 miux;
0071 unsigned long local_wks;
0072 unsigned long local_sdp;
0073 unsigned long local_sap;
0074 atomic_t local_sdp_cnt[LLCP_SDP_NUM_SAP];
0075
0076
0077 u8 gb[NFC_MAX_GT_LEN];
0078 u8 gb_len;
0079
0080
0081 u8 remote_gb[NFC_MAX_GT_LEN];
0082 u8 remote_gb_len;
0083
0084 u8 remote_version;
0085 u16 remote_miu;
0086 u16 remote_lto;
0087 u8 remote_opt;
0088 u16 remote_wks;
0089
0090 struct mutex sdreq_lock;
0091 struct hlist_head pending_sdreqs;
0092 struct timer_list sdreq_timer;
0093 struct work_struct sdreq_timeout_work;
0094 u8 sdreq_next_tid;
0095
0096
0097 struct llcp_sock_list sockets;
0098 struct llcp_sock_list connecting_sockets;
0099 struct llcp_sock_list raw_sockets;
0100 };
0101
0102 struct nfc_llcp_sock {
0103 struct sock sk;
0104 struct nfc_dev *dev;
0105 struct nfc_llcp_local *local;
0106 u32 target_idx;
0107 u32 nfc_protocol;
0108
0109
0110 u8 ssap;
0111 u8 dsap;
0112 char *service_name;
0113 size_t service_name_len;
0114 u8 rw;
0115 __be16 miux;
0116
0117
0118
0119 u8 remote_rw;
0120 u16 remote_miu;
0121
0122
0123 u8 send_n;
0124 u8 send_ack_n;
0125 u8 recv_n;
0126 u8 recv_ack_n;
0127
0128
0129 u8 remote_ready;
0130
0131
0132 u8 reserved_ssap;
0133
0134 struct sk_buff_head tx_queue;
0135 struct sk_buff_head tx_pending_queue;
0136
0137 struct list_head accept_queue;
0138 struct sock *parent;
0139 };
0140
0141 struct nfc_llcp_ui_cb {
0142 __u8 dsap;
0143 __u8 ssap;
0144 };
0145
0146 #define nfc_llcp_ui_skb_cb(__skb) ((struct nfc_llcp_ui_cb *)&((__skb)->cb[0]))
0147
0148 #define nfc_llcp_sock(sk) ((struct nfc_llcp_sock *) (sk))
0149 #define nfc_llcp_dev(sk) (nfc_llcp_sock((sk))->dev)
0150
0151 #define LLCP_HEADER_SIZE 2
0152 #define LLCP_SEQUENCE_SIZE 1
0153 #define LLCP_AGF_PDU_HEADER_SIZE 2
0154
0155
0156 #define LLCP_VERSION_10 0x10
0157 #define LLCP_VERSION_11 0x11
0158
0159
0160 #define LLCP_PDU_SYMM 0x0
0161 #define LLCP_PDU_PAX 0x1
0162 #define LLCP_PDU_AGF 0x2
0163 #define LLCP_PDU_UI 0x3
0164 #define LLCP_PDU_CONNECT 0x4
0165 #define LLCP_PDU_DISC 0x5
0166 #define LLCP_PDU_CC 0x6
0167 #define LLCP_PDU_DM 0x7
0168 #define LLCP_PDU_FRMR 0x8
0169 #define LLCP_PDU_SNL 0x9
0170 #define LLCP_PDU_I 0xc
0171 #define LLCP_PDU_RR 0xd
0172 #define LLCP_PDU_RNR 0xe
0173
0174
0175 #define LLCP_TLV_VERSION 0x1
0176 #define LLCP_TLV_MIUX 0x2
0177 #define LLCP_TLV_WKS 0x3
0178 #define LLCP_TLV_LTO 0x4
0179 #define LLCP_TLV_RW 0x5
0180 #define LLCP_TLV_SN 0x6
0181 #define LLCP_TLV_OPT 0x7
0182 #define LLCP_TLV_SDREQ 0x8
0183 #define LLCP_TLV_SDRES 0x9
0184 #define LLCP_TLV_MAX 0xa
0185
0186
0187 #define LLCP_SAP_SDP 0x1
0188 #define LLCP_SAP_IP 0x2
0189 #define LLCP_SAP_OBEX 0x3
0190 #define LLCP_SAP_SNEP 0x4
0191 #define LLCP_SAP_MAX 0xff
0192
0193
0194 #define LLCP_DM_DISC 0x00
0195 #define LLCP_DM_NOCONN 0x01
0196 #define LLCP_DM_NOBOUND 0x02
0197 #define LLCP_DM_REJ 0x03
0198
0199
0200 void nfc_llcp_sock_link(struct llcp_sock_list *l, struct sock *s);
0201 void nfc_llcp_sock_unlink(struct llcp_sock_list *l, struct sock *s);
0202 void nfc_llcp_socket_remote_param_init(struct nfc_llcp_sock *sock);
0203 struct nfc_llcp_local *nfc_llcp_find_local(struct nfc_dev *dev);
0204 struct nfc_llcp_local *nfc_llcp_local_get(struct nfc_llcp_local *local);
0205 int nfc_llcp_local_put(struct nfc_llcp_local *local);
0206 u8 nfc_llcp_get_sdp_ssap(struct nfc_llcp_local *local,
0207 struct nfc_llcp_sock *sock);
0208 u8 nfc_llcp_get_local_ssap(struct nfc_llcp_local *local);
0209 void nfc_llcp_put_ssap(struct nfc_llcp_local *local, u8 ssap);
0210 int nfc_llcp_queue_i_frames(struct nfc_llcp_sock *sock);
0211 void nfc_llcp_send_to_raw_sock(struct nfc_llcp_local *local,
0212 struct sk_buff *skb, u8 direction);
0213
0214
0215 struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp, int kern);
0216 void nfc_llcp_sock_free(struct nfc_llcp_sock *sock);
0217 void nfc_llcp_accept_unlink(struct sock *sk);
0218 void nfc_llcp_accept_enqueue(struct sock *parent, struct sock *sk);
0219 struct sock *nfc_llcp_accept_dequeue(struct sock *sk, struct socket *newsock);
0220
0221
0222 int nfc_llcp_parse_gb_tlv(struct nfc_llcp_local *local,
0223 const u8 *tlv_array, u16 tlv_array_len);
0224 int nfc_llcp_parse_connection_tlv(struct nfc_llcp_sock *sock,
0225 const u8 *tlv_array, u16 tlv_array_len);
0226
0227
0228 void nfc_llcp_recv(void *data, struct sk_buff *skb, int err);
0229 u8 *nfc_llcp_build_tlv(u8 type, const u8 *value, u8 value_length, u8 *tlv_length);
0230 struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdres_tlv(u8 tid, u8 sap);
0231 struct nfc_llcp_sdp_tlv *nfc_llcp_build_sdreq_tlv(u8 tid, const char *uri,
0232 size_t uri_len);
0233 void nfc_llcp_free_sdp_tlv(struct nfc_llcp_sdp_tlv *sdp);
0234 void nfc_llcp_free_sdp_tlv_list(struct hlist_head *sdp_head);
0235 void nfc_llcp_recv(void *data, struct sk_buff *skb, int err);
0236 int nfc_llcp_send_symm(struct nfc_dev *dev);
0237 int nfc_llcp_send_connect(struct nfc_llcp_sock *sock);
0238 int nfc_llcp_send_cc(struct nfc_llcp_sock *sock);
0239 int nfc_llcp_send_snl_sdres(struct nfc_llcp_local *local,
0240 struct hlist_head *tlv_list, size_t tlvs_len);
0241 int nfc_llcp_send_snl_sdreq(struct nfc_llcp_local *local,
0242 struct hlist_head *tlv_list, size_t tlvs_len);
0243 int nfc_llcp_send_dm(struct nfc_llcp_local *local, u8 ssap, u8 dsap, u8 reason);
0244 int nfc_llcp_send_disconnect(struct nfc_llcp_sock *sock);
0245 int nfc_llcp_send_i_frame(struct nfc_llcp_sock *sock,
0246 struct msghdr *msg, size_t len);
0247 int nfc_llcp_send_ui_frame(struct nfc_llcp_sock *sock, u8 ssap, u8 dsap,
0248 struct msghdr *msg, size_t len);
0249 int nfc_llcp_send_rr(struct nfc_llcp_sock *sock);
0250
0251
0252 int __init nfc_llcp_sock_init(void);
0253 void nfc_llcp_sock_exit(void);