aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlan Elias <ilane@ti.com>2012-08-15 04:46:22 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-09-24 18:17:23 -0400
commit7e0352306f6869b442a574a8e691f126c9fe930a (patch)
tree3ceccb1a7f1467ebfbd83289c7df3ad020ac2906
parent5d50b364e61e85eb41938d25770db3aab5e07d82 (diff)
NFC: Set local general bytes in nci_start_poll
If initiator protocol is NFC-DEP, set the local general bytes in nci_start_poll. Signed-off-by: Ilan Elias <ilane@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--include/net/nfc/nci.h23
-rw-r--r--include/net/nfc/nci_core.h1
-rw-r--r--net/nfc/nci/core.c55
-rw-r--r--net/nfc/nci/rsp.c14
4 files changed, 93 insertions, 0 deletions
diff --git a/include/net/nfc/nci.h b/include/net/nfc/nci.h
index 276094b91d7c..d260ef3629db 100644
--- a/include/net/nfc/nci.h
+++ b/include/net/nfc/nci.h
@@ -32,6 +32,7 @@
32#define NCI_MAX_NUM_MAPPING_CONFIGS 10 32#define NCI_MAX_NUM_MAPPING_CONFIGS 10
33#define NCI_MAX_NUM_RF_CONFIGS 10 33#define NCI_MAX_NUM_RF_CONFIGS 10
34#define NCI_MAX_NUM_CONN 10 34#define NCI_MAX_NUM_CONN 10
35#define NCI_MAX_PARAM_LEN 251
35 36
36/* NCI Status Codes */ 37/* NCI Status Codes */
37#define NCI_STATUS_OK 0x00 38#define NCI_STATUS_OK 0x00
@@ -102,6 +103,9 @@
102#define NCI_RF_INTERFACE_ISO_DEP 0x02 103#define NCI_RF_INTERFACE_ISO_DEP 0x02
103#define NCI_RF_INTERFACE_NFC_DEP 0x03 104#define NCI_RF_INTERFACE_NFC_DEP 0x03
104 105
106/* NCI Configuration Parameter Tags */
107#define NCI_PN_ATR_REQ_GEN_BYTES 0x29
108
105/* NCI Reset types */ 109/* NCI Reset types */
106#define NCI_RESET_TYPE_KEEP_CONFIG 0x00 110#define NCI_RESET_TYPE_KEEP_CONFIG 0x00
107#define NCI_RESET_TYPE_RESET_CONFIG 0x01 111#define NCI_RESET_TYPE_RESET_CONFIG 0x01
@@ -188,6 +192,18 @@ struct nci_core_reset_cmd {
188 192
189#define NCI_OP_CORE_INIT_CMD nci_opcode_pack(NCI_GID_CORE, 0x01) 193#define NCI_OP_CORE_INIT_CMD nci_opcode_pack(NCI_GID_CORE, 0x01)
190 194
195#define NCI_OP_CORE_SET_CONFIG_CMD nci_opcode_pack(NCI_GID_CORE, 0x02)
196struct set_config_param {
197 __u8 id;
198 __u8 len;
199 __u8 val[NCI_MAX_PARAM_LEN];
200} __packed;
201
202struct nci_core_set_config_cmd {
203 __u8 num_params;
204 struct set_config_param param; /* support 1 param per cmd is enough */
205} __packed;
206
191#define NCI_OP_RF_DISCOVER_MAP_CMD nci_opcode_pack(NCI_GID_RF_MGMT, 0x00) 207#define NCI_OP_RF_DISCOVER_MAP_CMD nci_opcode_pack(NCI_GID_RF_MGMT, 0x00)
192struct disc_map_config { 208struct disc_map_config {
193 __u8 rf_protocol; 209 __u8 rf_protocol;
@@ -252,6 +268,13 @@ struct nci_core_init_rsp_2 {
252 __le32 manufact_specific_info; 268 __le32 manufact_specific_info;
253} __packed; 269} __packed;
254 270
271#define NCI_OP_CORE_SET_CONFIG_RSP nci_opcode_pack(NCI_GID_CORE, 0x02)
272struct nci_core_set_config_rsp {
273 __u8 status;
274 __u8 num_params;
275 __u8 params_id[0]; /* variable size array */
276} __packed;
277
255#define NCI_OP_RF_DISCOVER_MAP_RSP nci_opcode_pack(NCI_GID_RF_MGMT, 0x00) 278#define NCI_OP_RF_DISCOVER_MAP_RSP nci_opcode_pack(NCI_GID_RF_MGMT, 0x00)
256 279
257#define NCI_OP_RF_DISCOVER_RSP nci_opcode_pack(NCI_GID_RF_MGMT, 0x03) 280#define NCI_OP_RF_DISCOVER_RSP nci_opcode_pack(NCI_GID_RF_MGMT, 0x03)
diff --git a/include/net/nfc/nci_core.h b/include/net/nfc/nci_core.h
index feba74027ff8..f98674d7baf1 100644
--- a/include/net/nfc/nci_core.h
+++ b/include/net/nfc/nci_core.h
@@ -54,6 +54,7 @@ enum nci_state {
54/* NCI timeouts */ 54/* NCI timeouts */
55#define NCI_RESET_TIMEOUT 5000 55#define NCI_RESET_TIMEOUT 5000
56#define NCI_INIT_TIMEOUT 5000 56#define NCI_INIT_TIMEOUT 5000
57#define NCI_SET_CONFIG_TIMEOUT 5000
57#define NCI_RF_DISC_TIMEOUT 5000 58#define NCI_RF_DISC_TIMEOUT 5000
58#define NCI_RF_DISC_SELECT_TIMEOUT 5000 59#define NCI_RF_DISC_SELECT_TIMEOUT 5000
59#define NCI_RF_DEACTIVATE_TIMEOUT 30000 60#define NCI_RF_DEACTIVATE_TIMEOUT 30000
diff --git a/net/nfc/nci/core.c b/net/nfc/nci/core.c
index f81efe13985a..f017b781667a 100644
--- a/net/nfc/nci/core.c
+++ b/net/nfc/nci/core.c
@@ -176,6 +176,27 @@ static void nci_init_complete_req(struct nci_dev *ndev, unsigned long opt)
176 (1 + ((*num) * sizeof(struct disc_map_config))), &cmd); 176 (1 + ((*num) * sizeof(struct disc_map_config))), &cmd);
177} 177}
178 178
179struct nci_set_config_param {
180 __u8 id;
181 size_t len;
182 __u8 *val;
183};
184
185static void nci_set_config_req(struct nci_dev *ndev, unsigned long opt)
186{
187 struct nci_set_config_param *param = (struct nci_set_config_param *)opt;
188 struct nci_core_set_config_cmd cmd;
189
190 BUG_ON(param->len > NCI_MAX_PARAM_LEN);
191
192 cmd.num_params = 1;
193 cmd.param.id = param->id;
194 cmd.param.len = param->len;
195 memcpy(cmd.param.val, param->val, param->len);
196
197 nci_send_cmd(ndev, NCI_OP_CORE_SET_CONFIG_CMD, (3 + param->len), &cmd);
198}
199
179static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) 200static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt)
180{ 201{
181 struct nci_rf_disc_cmd cmd; 202 struct nci_rf_disc_cmd cmd;
@@ -388,6 +409,32 @@ static int nci_dev_down(struct nfc_dev *nfc_dev)
388 return nci_close_device(ndev); 409 return nci_close_device(ndev);
389} 410}
390 411
412static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev)
413{
414 struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
415 struct nci_set_config_param param;
416 __u8 local_gb[NFC_MAX_GT_LEN];
417 int i, rc = 0;
418
419 param.val = nfc_get_local_general_bytes(nfc_dev, &param.len);
420 if ((param.val == NULL) || (param.len == 0))
421 return rc;
422
423 if (param.len > NCI_MAX_PARAM_LEN)
424 return -EINVAL;
425
426 for (i = 0; i < param.len; i++)
427 local_gb[param.len-1-i] = param.val[i];
428
429 param.id = NCI_PN_ATR_REQ_GEN_BYTES;
430 param.val = local_gb;
431
432 rc = nci_request(ndev, nci_set_config_req, (unsigned long)&param,
433 msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT));
434
435 return rc;
436}
437
391static int nci_start_poll(struct nfc_dev *nfc_dev, 438static int nci_start_poll(struct nfc_dev *nfc_dev,
392 __u32 im_protocols, __u32 tm_protocols) 439 __u32 im_protocols, __u32 tm_protocols)
393{ 440{
@@ -415,6 +462,14 @@ static int nci_start_poll(struct nfc_dev *nfc_dev,
415 return -EBUSY; 462 return -EBUSY;
416 } 463 }
417 464
465 if (im_protocols & NFC_PROTO_NFC_DEP_MASK) {
466 rc = nci_set_local_general_bytes(nfc_dev);
467 if (rc) {
468 pr_err("failed to set local general bytes\n");
469 return rc;
470 }
471 }
472
418 rc = nci_request(ndev, nci_rf_discover_req, im_protocols, 473 rc = nci_request(ndev, nci_rf_discover_req, im_protocols,
419 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT)); 474 msecs_to_jiffies(NCI_RF_DISC_TIMEOUT));
420 475
diff --git a/net/nfc/nci/rsp.c b/net/nfc/nci/rsp.c
index 3003c3390e49..dd072f38ad00 100644
--- a/net/nfc/nci/rsp.c
+++ b/net/nfc/nci/rsp.c
@@ -119,6 +119,16 @@ exit:
119 nci_req_complete(ndev, rsp_1->status); 119 nci_req_complete(ndev, rsp_1->status);
120} 120}
121 121
122static void nci_core_set_config_rsp_packet(struct nci_dev *ndev,
123 struct sk_buff *skb)
124{
125 struct nci_core_set_config_rsp *rsp = (void *) skb->data;
126
127 pr_debug("status 0x%x\n", rsp->status);
128
129 nci_req_complete(ndev, rsp->status);
130}
131
122static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev, 132static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
123 struct sk_buff *skb) 133 struct sk_buff *skb)
124{ 134{
@@ -194,6 +204,10 @@ void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
194 nci_core_init_rsp_packet(ndev, skb); 204 nci_core_init_rsp_packet(ndev, skb);
195 break; 205 break;
196 206
207 case NCI_OP_CORE_SET_CONFIG_RSP:
208 nci_core_set_config_rsp_packet(ndev, skb);
209 break;
210
197 case NCI_OP_RF_DISCOVER_MAP_RSP: 211 case NCI_OP_RF_DISCOVER_MAP_RSP:
198 nci_rf_disc_map_rsp_packet(ndev, skb); 212 nci_rf_disc_map_rsp_packet(ndev, skb);
199 break; 213 break;