Samuel Ortiz <sameo@linux.intel.com> says: "NFC: 3.19 pull request This is the NFC pull request for 3.19. With this one we get: - NFC digital improvements for DEP support: Chaining, NACK and ATN support added. - NCI improvements: Support for p2p target, SE IO operand addition, SE operands extensions to support proprietary implementations, and a few fixes. - NFC HCI improvements: OPEN_PIPE and NOTIFY_ALL_CLEARED support, and SE IO operand addition. - A bunch of minor improvements and fixes for STMicro st21nfcb and st21nfca"
Unified · Split
| @@ -29,8 +29,8 @@ · 28 unmodified lines | ||
| 29 | 29 | #include <linux/delay.h> |
| 30 | 30 | #include <linux/nfc.h> |
| 31 | 31 | #include <linux/firmware.h> |
| 32 | −#include <linux/unaligned/access_ok.h> | |
| 33 | 32 | #include <linux/platform_data/pn544.h> |
| 33 | +#include <asm/unaligned.h> | |
| 34 | 34 | |
| 35 | 35 | #include <net/nfc/hci.h> |
| 36 | 36 | #include <net/nfc/llc.h> |
| @@ -28,8 +28,8 @@ · 27 unmodified lines | ||
| 28 | 28 | #include <linux/delay.h> |
| 29 | 29 | #include <linux/nfc.h> |
| 30 | 30 | #include <linux/firmware.h> |
| 31 | −#include <linux/unaligned/access_ok.h> | |
| 32 | 31 | #include <linux/platform_data/st21nfca.h> |
| 32 | +#include <asm/unaligned.h> | |
| 33 | 33 | |
| 34 | 34 | #include <net/nfc/hci.h> |
| 35 | 35 | #include <net/nfc/llc.h> |
| @@ -72,7 +72,6 @@ struct st21nfca_i2c_phy { · 36 unmodified lines | ||
| 72 | 72 | struct nfc_hci_dev *hdev; |
| 73 | 73 | |
| 74 | 74 | unsigned int gpio_ena; |
| 75 | − unsigned int gpio_irq; | |
| 76 | 75 | unsigned int irq_polarity; |
| 77 | 76 | |
| 78 | 77 | struct sk_buff *pending_skb; |
| @@ -531,20 +530,12 @@ static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client) · 452 unmodified lines | ||
| 531 | 530 | "clf_enable"); |
| 532 | 531 | if (r) { |
| 533 | 532 | nfc_err(&client->dev, "Failed to request enable pin\n"); |
| 534 | − return -ENODEV; | |
| 533 | + return r; | |
| 535 | 534 | } |
| 536 | 535 | |
| 537 | 536 | phy->gpio_ena = gpio; |
| 538 | 537 | |
| 539 | − /* IRQ */ | |
| 540 | − r = irq_of_parse_and_map(pp, 0); | |
| 541 | − if (r < 0) { | |
| 542 | − nfc_err(&client->dev, "Unable to get irq, error: %d\n", r); | |
| 543 | − return r; | |
| 544 | − } | |
| 545 | − | |
| 546 | − phy->irq_polarity = irq_get_trigger_type(r); | |
| 547 | − client->irq = r; | |
| 538 | + phy->irq_polarity = irq_get_trigger_type(client->irq); | |
| 548 | 539 | |
| 549 | 540 | return 0; |
| 550 | 541 | } |
| @@ -560,7 +551,6 @@ static int st21nfca_hci_i2c_request_resources(struct i2c_client *client) · 9 unmodified lines | ||
| 560 | 551 | struct st21nfca_nfc_platform_data *pdata; |
| 561 | 552 | struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client); |
| 562 | 553 | int r; |
| 563 | − int irq; | |
| 564 | 554 | |
| 565 | 555 | pdata = client->dev.platform_data; |
| 566 | 556 | if (pdata == NULL) { |
| @@ -569,36 +559,18 @@ static int st21nfca_hci_i2c_request_resources(struct i2c_client *client) · 2 unmodified lines | ||
| 569 | 559 | } |
| 570 | 560 | |
| 571 | 561 | /* store for later use */ |
| 572 | − phy->gpio_irq = pdata->gpio_irq; | |
| 573 | 562 | phy->gpio_ena = pdata->gpio_ena; |
| 574 | 563 | phy->irq_polarity = pdata->irq_polarity; |
| 575 | 564 | |
| 576 | − r = devm_gpio_request_one(&client->dev, phy->gpio_irq, GPIOF_IN, | |
| 577 | − "wake_up"); | |
| 578 | − if (r) { | |
| 579 | − pr_err("%s : gpio_request failed\n", __FILE__); | |
| 580 | − return -ENODEV; | |
| 581 | − } | |
| 582 | − | |
| 583 | 565 | if (phy->gpio_ena > 0) { |
| 584 | 566 | r = devm_gpio_request_one(&client->dev, phy->gpio_ena, |
| 585 | 567 | GPIOF_OUT_INIT_HIGH, "clf_enable"); |
| 586 | 568 | if (r) { |
| 587 | 569 | pr_err("%s : ena gpio_request failed\n", __FILE__); |
| 588 | − return -ENODEV; | |
| 570 | + return r; | |
| 589 | 571 | } |
| 590 | 572 | } |
| 591 | 573 | |
| 592 | − /* IRQ */ | |
| 593 | − irq = gpio_to_irq(phy->gpio_irq); | |
| 594 | − if (irq < 0) { | |
| 595 | − nfc_err(&client->dev, | |
| 596 | − "Unable to get irq number for GPIO %d error %d\n", | |
| 597 | − phy->gpio_irq, r); | |
| 598 | − return -ENODEV; | |
| 599 | − } | |
| 600 | − client->irq = irq; | |
| 601 | − | |
| 602 | 574 | return 0; |
| 603 | 575 | } |
| 604 | 576 | |
| @@ -656,7 +628,7 @@ static int st21nfca_hci_i2c_probe(struct i2c_client *client, · 51 unmodified lines | ||
| 656 | 628 | r = st21nfca_hci_platform_init(phy); |
| 657 | 629 | if (r < 0) { |
| 658 | 630 | nfc_err(&client->dev, "Unable to reboot st21nfca\n"); |
| 659 | − return -ENODEV; | |
| 631 | + return r; | |
| 660 | 632 | } |
| 661 | 633 | |
| 662 | 634 | r = devm_request_threaded_irq(&client->dev, client->irq, NULL, |
| @@ -687,10 +659,13 @@ static int st21nfca_hci_i2c_remove(struct i2c_client *client) · 24 unmodified lines | ||
| 687 | 659 | return 0; |
| 688 | 660 | } |
| 689 | 661 | |
| 662 | +#ifdef CONFIG_OF | |
| 690 | 663 | static const struct of_device_id of_st21nfca_i2c_match[] = { |
| 691 | 664 | { .compatible = "st,st21nfca_i2c", }, |
| 692 | 665 | {} |
| 693 | 666 | }; |
| 667 | +MODULE_DEVICE_TABLE(of, of_st21nfca_i2c_match); | |
| 668 | +#endif | |
| 694 | 669 | |
| 695 | 670 | static struct i2c_driver st21nfca_hci_i2c_driver = { |
| 696 | 671 | .driver = { |
| @@ -77,10 +77,6 @@ · 76 unmodified lines | ||
| 77 | 77 | ((p & 0x0f) == (ST21NFCA_DM_PIPE_CREATED | ST21NFCA_DM_PIPE_OPEN)) |
| 78 | 78 | |
| 79 | 79 | #define ST21NFCA_NFC_MODE 0x03 /* NFC_MODE parameter*/ |
| 80 | −#define ST21NFCA_EVT_FIELD_ON 0x11 | |
| 81 | −#define ST21NFCA_EVT_CARD_DEACTIVATED 0x12 | |
| 82 | −#define ST21NFCA_EVT_CARD_ACTIVATED 0x13 | |
| 83 | −#define ST21NFCA_EVT_FIELD_OFF 0x14 | |
| 84 | 80 | |
| 85 | 81 | static DECLARE_BITMAP(dev_mask, ST21NFCA_NUM_DEVICES); |
| 86 | 82 | |
| @@ -841,31 +837,11 @@ static int st21nfca_hci_check_presence(struct nfc_hci_dev *hdev, · 754 unmodified lines | ||
| 841 | 837 | static int st21nfca_hci_event_received(struct nfc_hci_dev *hdev, u8 gate, |
| 842 | 838 | u8 event, struct sk_buff *skb) |
| 843 | 839 | { |
| 844 | − int r; | |
| 845 | − struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev); | |
| 846 | − | |
| 847 | − pr_debug("hci event: %d\n", event); | |
| 840 | + pr_debug("hci event: %d gate: %x\n", event, gate); | |
| 848 | 841 | |
| 849 | − switch (event) { | |
| 850 | − case ST21NFCA_EVT_CARD_ACTIVATED: | |
| 851 | − if (gate == ST21NFCA_RF_CARD_F_GATE) | |
| 852 | − info->dep_info.curr_nfc_dep_pni = 0; | |
| 853 | − break; | |
| 854 | − case ST21NFCA_EVT_CARD_DEACTIVATED: | |
| 855 | − break; | |
| 856 | − case ST21NFCA_EVT_FIELD_ON: | |
| 857 | − break; | |
| 858 | − case ST21NFCA_EVT_FIELD_OFF: | |
| 859 | − break; | |
| 860 | − case ST21NFCA_EVT_SEND_DATA: | |
| 861 | − if (gate == ST21NFCA_RF_CARD_F_GATE) { | |
| 862 | − r = st21nfca_tm_event_send_data(hdev, skb, gate); | |
| 863 | − if (r < 0) | |
| 864 | − return r; | |
| 865 | − return 0; | |
| 866 | − } | |
| 867 | − info->dep_info.curr_nfc_dep_pni = 0; | |
| 868 | − return 1; | |
| 842 | + switch (gate) { | |
| 843 | + case ST21NFCA_RF_CARD_F_GATE: | |
| 844 | + return st21nfca_dep_event_received(hdev, event, skb); | |
| 869 | 845 | default: |
| 870 | 846 | return 1; |
| 871 | 847 | } |
| @@ -85,6 +85,4 @@ struct st21nfca_hci_info { · 84 unmodified lines | ||
| 85 | 85 | |
| 86 | 86 | #define ST21NFCA_RF_CARD_F_GATE 0x24 |
| 87 | 87 | |
| 88 | −#define ST21NFCA_EVT_SEND_DATA 0x10 | |
| 89 | − | |
| 90 | 88 | #endif /* __LOCAL_ST21NFCA_H_ */ |
| @@ -49,6 +49,12 @@ · 48 unmodified lines | ||
| 49 | 49 | #define ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B 0x30 |
| 50 | 50 | #define ST21NFCA_GB_BIT 0x02 |
| 51 | 51 | |
| 52 | +#define ST21NFCA_EVT_SEND_DATA 0x10 | |
| 53 | +#define ST21NFCA_EVT_FIELD_ON 0x11 | |
| 54 | +#define ST21NFCA_EVT_CARD_DEACTIVATED 0x12 | |
| 55 | +#define ST21NFCA_EVT_CARD_ACTIVATED 0x13 | |
| 56 | +#define ST21NFCA_EVT_FIELD_OFF 0x14 | |
| 57 | + | |
| 52 | 58 | #define ST21NFCA_EVT_CARD_F_BITRATE 0x16 |
| 53 | 59 | #define ST21NFCA_EVT_READER_F_BITRATE 0x13 |
| 54 | 60 | #define ST21NFCA_PSL_REQ_SEND_SPEED(brs) (brs & 0x38) |
| @@ -372,8 +378,8 @@ exit: · 317 unmodified lines | ||
| 372 | 378 | return r; |
| 373 | 379 | } |
| 374 | 380 | |
| 375 | −int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev, struct sk_buff *skb, | |
| 376 | − u8 gate) | |
| 381 | +static int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev, | |
| 382 | + struct sk_buff *skb) | |
| 377 | 383 | { |
| 378 | 384 | u8 cmd0, cmd1; |
| 379 | 385 | int r; |
| @@ -400,7 +406,42 @@ int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev, struct sk_buff *skb, · 20 unmodified lines | ||
| 400 | 406 | } |
| 401 | 407 | return r; |
| 402 | 408 | } |
| 403 | −EXPORT_SYMBOL(st21nfca_tm_event_send_data); | |
| 409 | + | |
| 410 | +/* | |
| 411 | + * Returns: | |
| 412 | + * <= 0: driver handled the event, skb consumed | |
| 413 | + * 1: driver does not handle the event, please do standard processing | |
| 414 | + */ | |
| 415 | +int st21nfca_dep_event_received(struct nfc_hci_dev *hdev, | |
| 416 | + u8 event, struct sk_buff *skb) | |
| 417 | +{ | |
| 418 | + int r = 0; | |
| 419 | + struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev); | |
| 420 | + | |
| 421 | + pr_debug("dep event: %d\n", event); | |
| 422 | + | |
| 423 | + switch (event) { | |
| 424 | + case ST21NFCA_EVT_CARD_ACTIVATED: | |
| 425 | + info->dep_info.curr_nfc_dep_pni = 0; | |
| 426 | + break; | |
| 427 | + case ST21NFCA_EVT_CARD_DEACTIVATED: | |
| 428 | + break; | |
| 429 | + case ST21NFCA_EVT_FIELD_ON: | |
| 430 | + break; | |
| 431 | + case ST21NFCA_EVT_FIELD_OFF: | |
| 432 | + break; | |
| 433 | + case ST21NFCA_EVT_SEND_DATA: | |
| 434 | + r = st21nfca_tm_event_send_data(hdev, skb); | |
| 435 | + if (r < 0) | |
| 436 | + return r; | |
| 437 | + return 0; | |
| 438 | + default: | |
| 439 | + return 1; | |
| 440 | + } | |
| 441 | + kfree_skb(skb); | |
| 442 | + return r; | |
| 443 | +} | |
| 444 | +EXPORT_SYMBOL(st21nfca_dep_event_received); | |
| 404 | 445 | |
| 405 | 446 | static void st21nfca_im_send_psl_req(struct nfc_hci_dev *hdev, u8 did, u8 bsi, |
| 406 | 447 | u8 bri, u8 lri) |
| @@ -32,8 +32,8 @@ struct st21nfca_dep_info { · 31 unmodified lines | ||
| 32 | 32 | u8 lri; |
| 33 | 33 | } __packed; |
| 34 | 34 | |
| 35 | −int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev, struct sk_buff *skb, | |
| 36 | − u8 gate); | |
| 35 | +int st21nfca_dep_event_received(struct nfc_hci_dev *hdev, | |
| 36 | + u8 event, struct sk_buff *skb); | |
| 37 | 37 | int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb); |
| 38 | 38 | |
| 39 | 39 | int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len); |
| @@ -50,7 +50,6 @@ struct st21nfcb_i2c_phy { · 49 unmodified lines | ||
| 50 | 50 | struct i2c_client *i2c_dev; |
| 51 | 51 | struct llt_ndlc *ndlc; |
| 52 | 52 | |
| 53 | − unsigned int gpio_irq; | |
| 54 | 53 | unsigned int gpio_reset; |
| 55 | 54 | unsigned int irq_polarity; |
| 56 | 55 | |
| @@ -81,8 +80,6 @@ static void st21nfcb_nci_i2c_disable(void *phy_id) · 24 unmodified lines | ||
| 81 | 80 | { |
| 82 | 81 | struct st21nfcb_i2c_phy *phy = phy_id; |
| 83 | 82 | |
| 84 | − pr_info("\n"); | |
| 85 | − | |
| 86 | 83 | phy->powered = 0; |
| 87 | 84 | /* reset chip in order to flush clf */ |
| 88 | 85 | gpio_set_value(phy->gpio_reset, 0); |
| @@ -258,19 +255,11 @@ static int st21nfcb_nci_i2c_of_request_resources(struct i2c_client *client) · 169 unmodified lines | ||
| 258 | 255 | GPIOF_OUT_INIT_HIGH, "clf_reset"); |
| 259 | 256 | if (r) { |
| 260 | 257 | nfc_err(&client->dev, "Failed to request reset pin\n"); |
| 261 | − return -ENODEV; | |
| 262 | − } | |
| 263 | − phy->gpio_reset = gpio; | |
| 264 | − | |
| 265 | − /* IRQ */ | |
| 266 | − r = irq_of_parse_and_map(pp, 0); | |
| 267 | − if (r < 0) { | |
| 268 | − nfc_err(&client->dev, "Unable to get irq, error: %d\n", r); | |
| 269 | 258 | return r; |
| 270 | 259 | } |
| 260 | + phy->gpio_reset = gpio; | |
| 271 | 261 | |
| 272 | − phy->irq_polarity = irq_get_trigger_type(r); | |
| 273 | − client->irq = r; | |
| 262 | + phy->irq_polarity = irq_get_trigger_type(client->irq); | |
| 274 | 263 | |
| 275 | 264 | return 0; |
| 276 | 265 | } |
| @@ -286,7 +275,6 @@ static int st21nfcb_nci_i2c_request_resources(struct i2c_client *client) · 9 unmodified lines | ||
| 286 | 275 | struct st21nfcb_nfc_platform_data *pdata; |
| 287 | 276 | struct st21nfcb_i2c_phy *phy = i2c_get_clientdata(client); |
| 288 | 277 | int r; |
| 289 | − int irq; | |
| 290 | 278 | |
| 291 | 279 | pdata = client->dev.platform_data; |
| 292 | 280 | if (pdata == NULL) { |
| @@ -295,33 +283,15 @@ static int st21nfcb_nci_i2c_request_resources(struct i2c_client *client) · 2 unmodified lines | ||
| 295 | 283 | } |
| 296 | 284 | |
| 297 | 285 | /* store for later use */ |
| 298 | − phy->gpio_irq = pdata->gpio_irq; | |
| 299 | 286 | phy->gpio_reset = pdata->gpio_reset; |
| 300 | 287 | phy->irq_polarity = pdata->irq_polarity; |
| 301 | 288 | |
| 302 | − r = devm_gpio_request_one(&client->dev, phy->gpio_irq, | |
| 303 | − GPIOF_IN, "clf_irq"); | |
| 304 | − if (r) { | |
| 305 | − pr_err("%s : gpio_request failed\n", __FILE__); | |
| 306 | − return -ENODEV; | |
| 307 | − } | |
| 308 | − | |
| 309 | 289 | r = devm_gpio_request_one(&client->dev, |
| 310 | 290 | phy->gpio_reset, GPIOF_OUT_INIT_HIGH, "clf_reset"); |
| 311 | 291 | if (r) { |
| 312 | 292 | pr_err("%s : reset gpio_request failed\n", __FILE__); |
| 313 | − return -ENODEV; | |
| 314 | − } | |
| 315 | − | |
| 316 | − /* IRQ */ | |
| 317 | − irq = gpio_to_irq(phy->gpio_irq); | |
| 318 | − if (irq < 0) { | |
| 319 | − nfc_err(&client->dev, | |
| 320 | − "Unable to get irq number for GPIO %d error %d\n", | |
| 321 | − phy->gpio_irq, r); | |
| 322 | − return -ENODEV; | |
| 293 | + return r; | |
| 323 | 294 | } |
| 324 | − client->irq = irq; | |
| 325 | 295 | |
| 326 | 296 | return 0; |
| 327 | 297 | } |
| @@ -401,10 +371,13 @@ static int st21nfcb_nci_i2c_remove(struct i2c_client *client) · 73 unmodified lines | ||
| 401 | 371 | return 0; |
| 402 | 372 | } |
| 403 | 373 | |
| 374 | +#ifdef CONFIG_OF | |
| 404 | 375 | static const struct of_device_id of_st21nfcb_i2c_match[] = { |
| 405 | 376 | { .compatible = "st,st21nfcb_i2c", }, |
| 406 | 377 | {} |
| 407 | 378 | }; |
| 379 | +MODULE_DEVICE_TABLE(of, of_st21nfcb_i2c_match); | |
| 380 | +#endif | |
| 408 | 381 | |
| 409 | 382 | static struct i2c_driver st21nfcb_nci_i2c_driver = { |
| 410 | 383 | .driver = { |
| @@ -266,7 +266,7 @@ int ndlc_probe(void *phy_id, struct nfc_phy_ops *phy_ops, struct device *dev, · 265 unmodified lines | ||
| 266 | 266 | |
| 267 | 267 | *ndlc_id = ndlc; |
| 268 | 268 | |
| 269 | − /* start timers */ | |
| 269 | + /* initialize timers */ | |
| 270 | 270 | init_timer(&ndlc->t1_timer); |
| 271 | 271 | ndlc->t1_timer.data = (unsigned long)ndlc; |
| 272 | 272 | ndlc->t1_timer.function = ndlc_t1_timeout; |
| @@ -24,7 +24,6 @@ · 23 unmodified lines | ||
| 24 | 24 | #define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci" |
| 25 | 25 | |
| 26 | 26 | struct st21nfca_nfc_platform_data { |
| 27 | − unsigned int gpio_irq; | |
| 28 | 27 | unsigned int gpio_ena; |
| 29 | 28 | unsigned int irq_polarity; |
| 30 | 29 | }; |
| @@ -24,7 +24,6 @@ · 23 unmodified lines | ||
| 24 | 24 | #define ST21NFCB_NCI_DRIVER_NAME "st21nfcb_nci" |
| 25 | 25 | |
| 26 | 26 | struct st21nfcb_nfc_platform_data { |
| 27 | − unsigned int gpio_irq; | |
| 28 | 27 | unsigned int gpio_reset; |
| 29 | 28 | unsigned int irq_polarity; |
| 30 | 29 | }; |
| @@ -225,6 +225,19 @@ struct nfc_digital_dev { · 224 unmodified lines | ||
| 225 | 225 | u8 curr_protocol; |
| 226 | 226 | u8 curr_rf_tech; |
| 227 | 227 | u8 curr_nfc_dep_pni; |
| 228 | + u8 did; | |
| 229 | + | |
| 230 | + u8 local_payload_max; | |
| 231 | + u8 remote_payload_max; | |
| 232 | + | |
| 233 | + struct sk_buff *chaining_skb; | |
| 234 | + struct digital_data_exch *data_exch; | |
| 235 | + | |
| 236 | + int atn_count; | |
| 237 | + int nack_count; | |
| 238 | + | |
| 239 | + struct sk_buff *saved_skb; | |
| 240 | + unsigned int saved_skb_len; | |
| 228 | 241 | |
| 229 | 242 | u16 target_fsc; |
| 230 | 243 | |
| @@ -57,10 +57,14 @@ struct nfc_hci_ops { · 56 unmodified lines | ||
| 57 | 57 | int (*discover_se)(struct nfc_hci_dev *dev); |
| 58 | 58 | int (*enable_se)(struct nfc_hci_dev *dev, u32 se_idx); |
| 59 | 59 | int (*disable_se)(struct nfc_hci_dev *dev, u32 se_idx); |
| 60 | + int (*se_io)(struct nfc_hci_dev *dev, u32 se_idx, | |
| 61 | + u8 *apdu, size_t apdu_length, | |
| 62 | + se_io_cb_t cb, void *cb_context); | |
| 60 | 63 | }; |
| 61 | 64 | |
| 62 | 65 | /* Pipes */ |
| 63 | 66 | #define NFC_HCI_INVALID_PIPE 0x80 |
| 67 | +#define NFC_HCI_DO_NOT_CREATE_PIPE 0x81 | |
| 64 | 68 | #define NFC_HCI_LINK_MGMT_PIPE 0x00 |
| 65 | 69 | #define NFC_HCI_ADMIN_PIPE 0x01 |
| 66 | 70 | |
| @@ -28,6 +28,8 @@ · 27 unmodified lines | ||
| 28 | 28 | #ifndef __NCI_H |
| 29 | 29 | #define __NCI_H |
| 30 | 30 | |
| 31 | +#include <net/nfc/nfc.h> | |
| 32 | + | |
| 31 | 33 | /* NCI constants */ |
| 32 | 34 | #define NCI_MAX_NUM_MAPPING_CONFIGS 10 |
| 33 | 35 | #define NCI_MAX_NUM_RF_CONFIGS 10 |
| @@ -73,6 +75,8 @@ · 39 unmodified lines | ||
| 73 | 75 | #define NCI_NFC_A_ACTIVE_LISTEN_MODE 0x83 |
| 74 | 76 | #define NCI_NFC_F_ACTIVE_LISTEN_MODE 0x85 |
| 75 | 77 | |
| 78 | +#define NCI_RF_TECH_MODE_LISTEN_MASK 0x80 | |
| 79 | + | |
| 76 | 80 | /* NCI RF Technologies */ |
| 77 | 81 | #define NCI_NFC_RF_TECHNOLOGY_A 0x00 |
| 78 | 82 | #define NCI_NFC_RF_TECHNOLOGY_B 0x01 |
| @@ -106,6 +110,17 @@ · 27 unmodified lines | ||
| 106 | 110 | |
| 107 | 111 | /* NCI Configuration Parameter Tags */ |
| 108 | 112 | #define NCI_PN_ATR_REQ_GEN_BYTES 0x29 |
| 113 | +#define NCI_LN_ATR_RES_GEN_BYTES 0x61 | |
| 114 | +#define NCI_LA_SEL_INFO 0x32 | |
| 115 | +#define NCI_LF_PROTOCOL_TYPE 0x50 | |
| 116 | +#define NCI_LF_CON_BITR_F 0x54 | |
| 117 | + | |
| 118 | +/* NCI Configuration Parameters masks */ | |
| 119 | +#define NCI_LA_SEL_INFO_ISO_DEP_MASK 0x20 | |
| 120 | +#define NCI_LA_SEL_INFO_NFC_DEP_MASK 0x40 | |
| 121 | +#define NCI_LF_PROTOCOL_TYPE_NFC_DEP_MASK 0x02 | |
| 122 | +#define NCI_LF_CON_BITR_F_212 0x02 | |
| 123 | +#define NCI_LF_CON_BITR_F_424 0x04 | |
| 109 | 124 | |
| 110 | 125 | /* NCI Reset types */ |
| 111 | 126 | #define NCI_RESET_TYPE_KEEP_CONFIG 0x00 |
| @@ -314,26 +329,31 @@ struct nci_core_intf_error_ntf { · 202 unmodified lines | ||
| 314 | 329 | struct rf_tech_specific_params_nfca_poll { |
| 315 | 330 | __u16 sens_res; |
| 316 | 331 | __u8 nfcid1_len; /* 0, 4, 7, or 10 Bytes */ |
| 317 | − __u8 nfcid1[10]; | |
| 332 | + __u8 nfcid1[NFC_NFCID1_MAXSIZE]; | |
| 318 | 333 | __u8 sel_res_len; /* 0 or 1 Bytes */ |
| 319 | 334 | __u8 sel_res; |
| 320 | 335 | } __packed; |
| 321 | 336 | |
| 322 | 337 | struct rf_tech_specific_params_nfcb_poll { |
| 323 | 338 | __u8 sensb_res_len; |
| 324 | − __u8 sensb_res[12]; /* 11 or 12 Bytes */ | |
| 339 | + __u8 sensb_res[NFC_SENSB_RES_MAXSIZE]; /* 11 or 12 Bytes */ | |
| 325 | 340 | } __packed; |
| 326 | 341 | |
| 327 | 342 | struct rf_tech_specific_params_nfcf_poll { |
| 328 | 343 | __u8 bit_rate; |
| 329 | 344 | __u8 sensf_res_len; |
| 330 | − __u8 sensf_res[18]; /* 16 or 18 Bytes */ | |
| 345 | + __u8 sensf_res[NFC_SENSF_RES_MAXSIZE]; /* 16 or 18 Bytes */ | |
| 331 | 346 | } __packed; |
| 332 | 347 | |
| 333 | 348 | struct rf_tech_specific_params_nfcv_poll { |
| 334 | 349 | __u8 res_flags; |
| 335 | 350 | __u8 dsfid; |
| 336 | − __u8 uid[8]; /* 8 Bytes */ | |
| 351 | + __u8 uid[NFC_ISO15693_UID_MAXSIZE]; /* 8 Bytes */ | |
| 352 | +} __packed; | |
| 353 | + | |
| 354 | +struct rf_tech_specific_params_nfcf_listen { | |
| 355 | + __u8 local_nfcid2_len; | |
| 356 | + __u8 local_nfcid2[NFC_NFCID2_MAXSIZE]; /* 0 or 8 Bytes */ | |
| 337 | 357 | } __packed; |
| 338 | 358 | |
| 339 | 359 | struct nci_rf_discover_ntf { |
| @@ -365,7 +385,12 @@ struct activation_params_nfcb_poll_iso_dep { · 25 unmodified lines | ||
| 365 | 385 | |
| 366 | 386 | struct activation_params_poll_nfc_dep { |
| 367 | 387 | __u8 atr_res_len; |
| 368 | − __u8 atr_res[63]; | |
| 388 | + __u8 atr_res[NFC_ATR_RES_MAXSIZE - 2]; /* ATR_RES from byte 3 */ | |
| 389 | +}; | |
| 390 | + | |
| 391 | +struct activation_params_listen_nfc_dep { | |
| 392 | + __u8 atr_req_len; | |
| 393 | + __u8 atr_req[NFC_ATR_REQ_MAXSIZE - 2]; /* ATR_REQ from byte 3 */ | |
| 369 | 394 | }; |
| 370 | 395 | |
| 371 | 396 | struct nci_rf_intf_activated_ntf { |
| @@ -382,6 +407,7 @@ struct nci_rf_intf_activated_ntf { · 10 unmodified lines | ||
| 382 | 407 | struct rf_tech_specific_params_nfcb_poll nfcb_poll; |
| 383 | 408 | struct rf_tech_specific_params_nfcf_poll nfcf_poll; |
| 384 | 409 | struct rf_tech_specific_params_nfcv_poll nfcv_poll; |
| 410 | + struct rf_tech_specific_params_nfcf_listen nfcf_listen; | |
| 385 | 411 | } rf_tech_specific_params; |
| 386 | 412 | |
| 387 | 413 | __u8 data_exch_rf_tech_and_mode; |
| @@ -393,6 +419,7 @@ struct nci_rf_intf_activated_ntf { · 5 unmodified lines | ||
| 393 | 419 | struct activation_params_nfca_poll_iso_dep nfca_poll_iso_dep; |
| 394 | 420 | struct activation_params_nfcb_poll_iso_dep nfcb_poll_iso_dep; |
| 395 | 421 | struct activation_params_poll_nfc_dep poll_nfc_dep; |
| 422 | + struct activation_params_listen_nfc_dep listen_nfc_dep; | |
| 396 | 423 | } activation_params; |
| 397 | 424 | |
| 398 | 425 | } __packed; |
| @@ -4,6 +4,7 @@ · 3 unmodified lines | ||
| 4 | 4 | * |
| 5 | 5 | * Copyright (C) 2011 Texas Instruments, Inc. |
| 6 | 6 | * Copyright (C) 2013 Intel Corporation. All rights reserved. |
| 7 | + * Copyright (C) 2014 Marvell International Ltd. | |
| 7 | 8 | * |
| 8 | 9 | * Written by Ilan Elias <ilane@ti.com> |
| 9 | 10 | * |
| @@ -49,6 +50,8 @@ enum nci_state { · 39 unmodified lines | ||
| 49 | 50 | NCI_W4_ALL_DISCOVERIES, |
| 50 | 51 | NCI_W4_HOST_SELECT, |
| 51 | 52 | NCI_POLL_ACTIVE, |
| 53 | + NCI_LISTEN_ACTIVE, | |
| 54 | + NCI_LISTEN_SLEEP, | |
| 52 | 55 | }; |
| 53 | 56 | |
| 54 | 57 | /* NCI timeouts */ |
| @@ -69,6 +72,12 @@ struct nci_ops { · 14 unmodified lines | ||
| 69 | 72 | int (*send)(struct nci_dev *ndev, struct sk_buff *skb); |
| 70 | 73 | int (*setup)(struct nci_dev *ndev); |
| 71 | 74 | __u32 (*get_rfprotocol)(struct nci_dev *ndev, __u8 rf_protocol); |
| 75 | + int (*discover_se)(struct nci_dev *ndev); | |
| 76 | + int (*disable_se)(struct nci_dev *ndev, u32 se_idx); | |
| 77 | + int (*enable_se)(struct nci_dev *ndev, u32 se_idx); | |
| 78 | + int (*se_io)(struct nci_dev *ndev, u32 se_idx, | |
| 79 | + u8 *apdu, size_t apdu_length, | |
| 80 | + se_io_cb_t cb, void *cb_context); | |
| 72 | 81 | }; |
| 73 | 82 | |
| 74 | 83 | #define NCI_MAX_SUPPORTED_RF_INTERFACES 4 |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | * Copyright (C) 2011 Instituto Nokia de Tecnologia |
| 3 | + * Copyright (C) 2014 Marvell International Ltd. | |
| 3 | 4 | * |
| 4 | 5 | * Authors: |
| 5 | 6 | * Lauro Ramos Venancio <lauro.venancio@openbossa.org> |
| @@ -87,6 +88,7 @@ struct nfc_ops { · 81 unmodified lines | ||
| 87 | 88 | #define NFC_TARGET_IDX_ANY -1 |
| 88 | 89 | #define NFC_MAX_GT_LEN 48 |
| 89 | 90 | #define NFC_ATR_RES_GT_OFFSET 15 |
| 91 | +#define NFC_ATR_REQ_GT_OFFSET 14 | |
| 90 | 92 | |
| 91 | 93 | /** |
| 92 | 94 | * struct nfc_target - NFC target descriptiom |
| @@ -116,6 +116,7 @@ enum nfc_commands { · 115 unmodified lines | ||
| 116 | 116 | NFC_EVENT_SE_TRANSACTION, |
| 117 | 117 | NFC_CMD_GET_SE, |
| 118 | 118 | NFC_CMD_SE_IO, |
| 119 | + NFC_CMD_ACTIVATE_TARGET, | |
| 119 | 120 | /* private: internal use only */ |
| 120 | 121 | __NFC_CMD_AFTER_LAST |
| 121 | 122 | }; |
| @@ -196,15 +197,19 @@ enum nfc_sdp_attr { · 74 unmodified lines | ||
| 196 | 197 | }; |
| 197 | 198 | #define NFC_SDP_ATTR_MAX (__NFC_SDP_ATTR_AFTER_LAST - 1) |
| 198 | 199 | |
| 199 | −#define NFC_DEVICE_NAME_MAXSIZE 8 | |
| 200 | −#define NFC_NFCID1_MAXSIZE 10 | |
| 201 | −#define NFC_NFCID2_MAXSIZE 8 | |
| 202 | −#define NFC_NFCID3_MAXSIZE 10 | |
| 203 | −#define NFC_SENSB_RES_MAXSIZE 12 | |
| 204 | −#define NFC_SENSF_RES_MAXSIZE 18 | |
| 205 | −#define NFC_GB_MAXSIZE 48 | |
| 206 | −#define NFC_FIRMWARE_NAME_MAXSIZE 32 | |
| 207 | −#define NFC_ISO15693_UID_MAXSIZE 8 | |
| 200 | +#define NFC_DEVICE_NAME_MAXSIZE 8 | |
| 201 | +#define NFC_NFCID1_MAXSIZE 10 | |
| 202 | +#define NFC_NFCID2_MAXSIZE 8 | |
| 203 | +#define NFC_NFCID3_MAXSIZE 10 | |
| 204 | +#define NFC_SENSB_RES_MAXSIZE 12 | |
| 205 | +#define NFC_SENSF_RES_MAXSIZE 18 | |
| 206 | +#define NFC_ATR_REQ_MAXSIZE 64 | |
| 207 | +#define NFC_ATR_RES_MAXSIZE 64 | |
| 208 | +#define NFC_ATR_REQ_GB_MAXSIZE 48 | |
| 209 | +#define NFC_ATR_RES_GB_MAXSIZE 47 | |
| 210 | +#define NFC_GB_MAXSIZE 48 | |
| 211 | +#define NFC_FIRMWARE_NAME_MAXSIZE 32 | |
| 212 | +#define NFC_ISO15693_UID_MAXSIZE 8 | |
| 208 | 213 | |
| 209 | 214 | /* NFC protocols */ |
| 210 | 215 | #define NFC_PROTO_JEWEL 1 |
| @@ -17,6 +17,9 @@ · 16 unmodified lines | ||
| 17 | 17 | |
| 18 | 18 | #include "digital.h" |
| 19 | 19 | |
| 20 | +#define DIGITAL_NFC_DEP_N_RETRY_NACK 2 | |
| 21 | +#define DIGITAL_NFC_DEP_N_RETRY_ATN 2 | |
| 22 | + | |
| 20 | 23 | #define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4 |
| 21 | 24 | #define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5 |
| 22 | 25 | |
| @@ -32,20 +35,32 @@ · 9 unmodified lines | ||
| 32 | 35 | #define DIGITAL_ATR_REQ_MIN_SIZE 16 |
| 33 | 36 | #define DIGITAL_ATR_REQ_MAX_SIZE 64 |
| 34 | 37 | |
| 35 | −#define DIGITAL_LR_BITS_PAYLOAD_SIZE_254B 0x30 | |
| 36 | −#define DIGITAL_FSL_BITS_PAYLOAD_SIZE_254B \ | |
| 37 | − (DIGITAL_LR_BITS_PAYLOAD_SIZE_254B >> 4) | |
| 38 | +#define DIGITAL_DID_MAX 14 | |
| 39 | + | |
| 40 | +#define DIGITAL_PAYLOAD_SIZE_MAX 254 | |
| 41 | +#define DIGITAL_PAYLOAD_BITS_TO_PP(s) (((s) & 0x3) << 4) | |
| 42 | +#define DIGITAL_PAYLOAD_PP_TO_BITS(s) (((s) >> 4) & 0x3) | |
| 43 | +#define DIGITAL_PAYLOAD_BITS_TO_FSL(s) ((s) & 0x3) | |
| 44 | +#define DIGITAL_PAYLOAD_FSL_TO_BITS(s) ((s) & 0x3) | |
| 45 | + | |
| 38 | 46 | #define DIGITAL_GB_BIT 0x02 |
| 39 | 47 | |
| 48 | +#define DIGITAL_NFC_DEP_REQ_RES_HEADROOM 2 /* SoD: [SB (NFC-A)] + LEN */ | |
| 49 | +#define DIGITAL_NFC_DEP_REQ_RES_TAILROOM 2 /* EoD: 2-byte CRC */ | |
| 50 | + | |
| 40 | 51 | #define DIGITAL_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0) |
| 41 | 52 | |
| 42 | 53 | #define DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT 0x10 |
| 54 | +#define DIGITAL_NFC_DEP_PFB_MI_BIT 0x10 | |
| 55 | +#define DIGITAL_NFC_DEP_PFB_NACK_BIT 0x10 | |
| 56 | +#define DIGITAL_NFC_DEP_PFB_DID_BIT 0x04 | |
| 43 | 57 | |
| 44 | 58 | #define DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb) \ |
| 45 | 59 | ((pfb) & DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT) |
| 46 | −#define DIGITAL_NFC_DEP_MI_BIT_SET(pfb) ((pfb) & 0x10) | |
| 60 | +#define DIGITAL_NFC_DEP_MI_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_MI_BIT) | |
| 61 | +#define DIGITAL_NFC_DEP_NACK_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_NACK_BIT) | |
| 47 | 62 | #define DIGITAL_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08) |
| 48 | −#define DIGITAL_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & 0x04) | |
| 63 | +#define DIGITAL_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_DID_BIT) | |
| 49 | 64 | #define DIGITAL_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03) |
| 50 | 65 | |
| 51 | 66 | #define DIGITAL_NFC_DEP_PFB_I_PDU 0x00 |
| @@ -97,6 +112,34 @@ struct digital_dep_req_res { · 45 unmodified lines | ||
| 97 | 112 | |
| 98 | 113 | static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, |
| 99 | 114 | struct sk_buff *resp); |
| 115 | +static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, | |
| 116 | + struct sk_buff *resp); | |
| 117 | + | |
| 118 | +static const u8 digital_payload_bits_map[4] = { | |
| 119 | + [0] = 64, | |
| 120 | + [1] = 128, | |
| 121 | + [2] = 192, | |
| 122 | + [3] = 254 | |
| 123 | +}; | |
| 124 | + | |
| 125 | +static u8 digital_payload_bits_to_size(u8 payload_bits) | |
| 126 | +{ | |
| 127 | + if (payload_bits >= ARRAY_SIZE(digital_payload_bits_map)) | |
| 128 | + return 0; | |
| 129 | + | |
| 130 | + return digital_payload_bits_map[payload_bits]; | |
| 131 | +} | |
| 132 | + | |
| 133 | +static u8 digital_payload_size_to_bits(u8 payload_size) | |
| 134 | +{ | |
| 135 | + int i; | |
| 136 | + | |
| 137 | + for (i = 0; i < ARRAY_SIZE(digital_payload_bits_map); i++) | |
| 138 | + if (digital_payload_bits_map[i] == payload_size) | |
| 139 | + return i; | |
| 140 | + | |
| 141 | + return 0xff; | |
| 142 | +} | |
| 100 | 143 | |
| 101 | 144 | static void digital_skb_push_dep_sod(struct nfc_digital_dev *ddev, |
| 102 | 145 | struct sk_buff *skb) |
| @@ -129,6 +172,106 @@ static int digital_skb_pull_dep_sod(struct nfc_digital_dev *ddev, · 26 unmodified lines | ||
| 129 | 172 | return 0; |
| 130 | 173 | } |
| 131 | 174 | |
| 175 | +static struct sk_buff * | |
| 176 | +digital_send_dep_data_prep(struct nfc_digital_dev *ddev, struct sk_buff *skb, | |
| 177 | + struct digital_dep_req_res *dep_req_res, | |
| 178 | + struct digital_data_exch *data_exch) | |
| 179 | +{ | |
| 180 | + struct sk_buff *new_skb; | |
| 181 | + | |
| 182 | + if (skb->len > ddev->remote_payload_max) { | |
| 183 | + dep_req_res->pfb |= DIGITAL_NFC_DEP_PFB_MI_BIT; | |
| 184 | + | |
| 185 | + new_skb = digital_skb_alloc(ddev, ddev->remote_payload_max); | |
| 186 | + if (!new_skb) { | |
| 187 | + kfree_skb(ddev->chaining_skb); | |
| 188 | + ddev->chaining_skb = NULL; | |
| 189 | + | |
| 190 | + return ERR_PTR(-ENOMEM); | |
| 191 | + } | |
| 192 | + | |
| 193 | + skb_reserve(new_skb, ddev->tx_headroom + NFC_HEADER_SIZE + | |
| 194 | + DIGITAL_NFC_DEP_REQ_RES_HEADROOM); | |
| 195 | + memcpy(skb_put(new_skb, ddev->remote_payload_max), skb->data, | |
| 196 | + ddev->remote_payload_max); | |
| 197 | + skb_pull(skb, ddev->remote_payload_max); | |
| 198 | + | |
| 199 | + ddev->chaining_skb = skb; | |
| 200 | + ddev->data_exch = data_exch; | |
| 201 | + } else { | |
| 202 | + ddev->chaining_skb = NULL; | |
| 203 | + new_skb = skb; | |
| 204 | + } | |
| 205 | + | |
| 206 | + return new_skb; | |
| 207 | +} | |
| 208 | + | |
| 209 | +static struct sk_buff * | |
| 210 | +digital_recv_dep_data_gather(struct nfc_digital_dev *ddev, u8 pfb, | |
| 211 | + struct sk_buff *resp, | |
| 212 | + int (*send_ack)(struct nfc_digital_dev *ddev, | |
| 213 | + struct digital_data_exch | |
| 214 | + *data_exch), | |
| 215 | + struct digital_data_exch *data_exch) | |
| 216 | +{ | |
| 217 | + struct sk_buff *new_skb; | |
| 218 | + int rc; | |
| 219 | + | |
| 220 | + if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb) && (!ddev->chaining_skb)) { | |
| 221 | + ddev->chaining_skb = | |
| 222 | + nfc_alloc_recv_skb(8 * ddev->local_payload_max, | |
| 223 | + GFP_KERNEL); | |
| 224 | + if (!ddev->chaining_skb) { | |
| 225 | + rc = -ENOMEM; | |
| 226 | + goto error; | |
| 227 | + } | |
| 228 | + } | |
| 229 | + | |
| 230 | + if (ddev->chaining_skb) { | |
| 231 | + if (resp->len > skb_tailroom(ddev->chaining_skb)) { | |
| 232 | + new_skb = skb_copy_expand(ddev->chaining_skb, | |
| 233 | + skb_headroom( | |
| 234 | + ddev->chaining_skb), | |
| 235 | + 8 * ddev->local_payload_max, | |
| 236 | + GFP_KERNEL); | |
| 237 | + if (!new_skb) { | |
| 238 | + rc = -ENOMEM; | |
| 239 | + goto error; | |
| 240 | + } | |
| 241 | + | |
| 242 | + kfree_skb(ddev->chaining_skb); | |
| 243 | + ddev->chaining_skb = new_skb; | |
| 244 | + } | |
| 245 | + | |
| 246 | + memcpy(skb_put(ddev->chaining_skb, resp->len), resp->data, | |
| 247 | + resp->len); | |
| 248 | + | |
| 249 | + kfree_skb(resp); | |
| 250 | + resp = NULL; | |
| 251 | + | |
| 252 | + if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb)) { | |
| 253 | + rc = send_ack(ddev, data_exch); | |
| 254 | + if (rc) | |
| 255 | + goto error; | |
| 256 | + | |
| 257 | + return NULL; | |
| 258 | + } | |
| 259 | + | |
| 260 | + resp = ddev->chaining_skb; | |
| 261 | + ddev->chaining_skb = NULL; | |
| 262 | + } | |
| 263 | + | |
| 264 | + return resp; | |
| 265 | + | |
| 266 | +error: | |
| 267 | + kfree_skb(resp); | |
| 268 | + | |
| 269 | + kfree_skb(ddev->chaining_skb); | |
| 270 | + ddev->chaining_skb = NULL; | |
| 271 | + | |
| 272 | + return ERR_PTR(rc); | |
| 273 | +} | |
| 274 | + | |
| 132 | 275 | static void digital_in_recv_psl_res(struct nfc_digital_dev *ddev, void *arg, |
| 133 | 276 | struct sk_buff *resp) |
| 134 | 277 | { |
| @@ -198,6 +341,8 @@ static int digital_in_send_psl_req(struct nfc_digital_dev *ddev, · 63 unmodified lines | ||
| 198 | 341 | { |
| 199 | 342 | struct sk_buff *skb; |
| 200 | 343 | struct digital_psl_req *psl_req; |
| 344 | + int rc; | |
| 345 | + u8 payload_size, payload_bits; | |
| 201 | 346 | |
| 202 | 347 | skb = digital_skb_alloc(ddev, sizeof(*psl_req)); |
| 203 | 348 | if (!skb) |
| @@ -211,14 +356,24 @@ static int digital_in_send_psl_req(struct nfc_digital_dev *ddev, · 7 unmodified lines | ||
| 211 | 356 | psl_req->cmd = DIGITAL_CMD_PSL_REQ; |
| 212 | 357 | psl_req->did = 0; |
| 213 | 358 | psl_req->brs = (0x2 << 3) | 0x2; /* 424F both directions */ |
| 214 | − psl_req->fsl = DIGITAL_FSL_BITS_PAYLOAD_SIZE_254B; | |
| 359 | + | |
| 360 | + payload_size = min(ddev->local_payload_max, ddev->remote_payload_max); | |
| 361 | + payload_bits = digital_payload_size_to_bits(payload_size); | |
| 362 | + psl_req->fsl = DIGITAL_PAYLOAD_BITS_TO_FSL(payload_bits); | |
| 363 | + | |
| 364 | + ddev->local_payload_max = payload_size; | |
| 365 | + ddev->remote_payload_max = payload_size; | |
| 215 | 366 | |
| 216 | 367 | digital_skb_push_dep_sod(ddev, skb); |
| 217 | 368 | |
| 218 | 369 | ddev->skb_add_crc(skb); |
| 219 | 370 | |
| 220 | − return digital_in_send_cmd(ddev, skb, 500, digital_in_recv_psl_res, | |
| 221 | − target); | |
| 371 | + rc = digital_in_send_cmd(ddev, skb, 500, digital_in_recv_psl_res, | |
| 372 | + target); | |
| 373 | + if (rc) | |
| 374 | + kfree_skb(skb); | |
| 375 | + | |
| 376 | + return rc; | |
| 222 | 377 | } |
| 223 | 378 | |
| 224 | 379 | static void digital_in_recv_atr_res(struct nfc_digital_dev *ddev, void *arg, |
| @@ -226,7 +381,7 @@ static void digital_in_recv_atr_res(struct nfc_digital_dev *ddev, void *arg, · 1 unmodified line | ||
| 226 | 381 | { |
| 227 | 382 | struct nfc_target *target = arg; |
| 228 | 383 | struct digital_atr_res *atr_res; |
| 229 | − u8 gb_len; | |
| 384 | + u8 gb_len, payload_bits; | |
| 230 | 385 | int rc; |
| 231 | 386 | |
| 232 | 387 | if (IS_ERR(resp)) { |
| @@ -256,6 +411,14 @@ static void digital_in_recv_atr_res(struct nfc_digital_dev *ddev, void *arg, · 23 unmodified lines | ||
| 256 | 411 | |
| 257 | 412 | atr_res = (struct digital_atr_res *)resp->data; |
| 258 | 413 | |
| 414 | + payload_bits = DIGITAL_PAYLOAD_PP_TO_BITS(atr_res->pp); | |
| 415 | + ddev->remote_payload_max = digital_payload_bits_to_size(payload_bits); | |
| 416 | + | |
| 417 | + if (!ddev->remote_payload_max) { | |
| 418 | + rc = -EINVAL; | |
| 419 | + goto exit; | |
| 420 | + } | |
| 421 | + | |
| 259 | 422 | rc = nfc_set_remote_general_bytes(ddev->nfc_dev, atr_res->gb, gb_len); |
| 260 | 423 | if (rc) |
| 261 | 424 | goto exit; |
| @@ -286,6 +449,8 @@ int digital_in_send_atr_req(struct nfc_digital_dev *ddev, · 24 unmodified lines | ||
| 286 | 449 | struct sk_buff *skb; |
| 287 | 450 | struct digital_atr_req *atr_req; |
| 288 | 451 | uint size; |
| 452 | + int rc; | |
| 453 | + u8 payload_bits; | |
| 289 | 454 | |
| 290 | 455 | size = DIGITAL_ATR_REQ_MIN_SIZE + gb_len; |
| 291 | 456 | |
| @@ -314,7 +479,9 @@ int digital_in_send_atr_req(struct nfc_digital_dev *ddev, · 22 unmodified lines | ||
| 314 | 479 | atr_req->bs = 0; |
| 315 | 480 | atr_req->br = 0; |
| 316 | 481 | |
| 317 | − atr_req->pp = DIGITAL_LR_BITS_PAYLOAD_SIZE_254B; | |
| 482 | + ddev->local_payload_max = DIGITAL_PAYLOAD_SIZE_MAX; | |
| 483 | + payload_bits = digital_payload_size_to_bits(ddev->local_payload_max); | |
| 484 | + atr_req->pp = DIGITAL_PAYLOAD_BITS_TO_PP(payload_bits); | |
| 318 | 485 | |
| 319 | 486 | if (gb_len) { |
| 320 | 487 | atr_req->pp |= DIGITAL_GB_BIT; |
| @@ -325,8 +492,113 @@ int digital_in_send_atr_req(struct nfc_digital_dev *ddev, · 4 unmodified lines | ||
| 325 | 492 | |
| 326 | 493 | ddev->skb_add_crc(skb); |
| 327 | 494 | |
| 328 | − return digital_in_send_cmd(ddev, skb, 500, digital_in_recv_atr_res, | |
| 329 | − target); | |
| 495 | + rc = digital_in_send_cmd(ddev, skb, 500, digital_in_recv_atr_res, | |
| 496 | + target); | |
| 497 | + if (rc) | |
| 498 | + kfree_skb(skb); | |
| 499 | + | |
| 500 | + return rc; | |
| 501 | +} | |
| 502 | + | |
| 503 | +static int digital_in_send_ack(struct nfc_digital_dev *ddev, | |
| 504 | + struct digital_data_exch *data_exch) | |
| 505 | +{ | |
| 506 | + struct digital_dep_req_res *dep_req; | |
| 507 | + struct sk_buff *skb; | |
| 508 | + int rc; | |
| 509 | + | |
| 510 | + skb = digital_skb_alloc(ddev, 1); | |
| 511 | + if (!skb) | |
| 512 | + return -ENOMEM; | |
| 513 | + | |
| 514 | + skb_push(skb, sizeof(struct digital_dep_req_res)); | |
| 515 | + | |
| 516 | + dep_req = (struct digital_dep_req_res *)skb->data; | |
| 517 | + | |
| 518 | + dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; | |
| 519 | + dep_req->cmd = DIGITAL_CMD_DEP_REQ; | |
| 520 | + dep_req->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | | |
| 521 | + ddev->curr_nfc_dep_pni; | |
| 522 | + | |
| 523 | + digital_skb_push_dep_sod(ddev, skb); | |
| 524 | + | |
| 525 | + ddev->skb_add_crc(skb); | |
| 526 | + | |
| 527 | + ddev->saved_skb = skb_get(skb); | |
| 528 | + ddev->saved_skb_len = skb->len; | |
| 529 | + | |
| 530 | + rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, | |
| 531 | + data_exch); | |
| 532 | + if (rc) { | |
| 533 | + kfree_skb(skb); | |
| 534 | + kfree_skb(ddev->saved_skb); | |
| 535 | + ddev->saved_skb = NULL; | |
| 536 | + } | |
| 537 | + | |
| 538 | + return rc; | |
| 539 | +} | |
| 540 | + | |
| 541 | +static int digital_in_send_nack(struct nfc_digital_dev *ddev, | |
| 542 | + struct digital_data_exch *data_exch) | |
| 543 | +{ | |
| 544 | + struct digital_dep_req_res *dep_req; | |
| 545 | + struct sk_buff *skb; | |
| 546 | + int rc; | |
| 547 | + | |
| 548 | + skb = digital_skb_alloc(ddev, 1); | |
| 549 | + if (!skb) | |
| 550 | + return -ENOMEM; | |
| 551 | + | |
| 552 | + skb_push(skb, sizeof(struct digital_dep_req_res)); | |
| 553 | + | |
| 554 | + dep_req = (struct digital_dep_req_res *)skb->data; | |
| 555 | + | |
| 556 | + dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; | |
| 557 | + dep_req->cmd = DIGITAL_CMD_DEP_REQ; | |
| 558 | + dep_req->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | | |
| 559 | + DIGITAL_NFC_DEP_PFB_NACK_BIT | ddev->curr_nfc_dep_pni; | |
| 560 | + | |
| 561 | + digital_skb_push_dep_sod(ddev, skb); | |
| 562 | + | |
| 563 | + ddev->skb_add_crc(skb); | |
| 564 | + | |
| 565 | + rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, | |
| 566 | + data_exch); | |
| 567 | + if (rc) | |
| 568 | + kfree_skb(skb); | |
| 569 | + | |
| 570 | + return rc; | |
| 571 | +} | |
| 572 | + | |
| 573 | +static int digital_in_send_atn(struct nfc_digital_dev *ddev, | |
| 574 | + struct digital_data_exch *data_exch) | |
| 575 | +{ | |
| 576 | + struct digital_dep_req_res *dep_req; | |
| 577 | + struct sk_buff *skb; | |
| 578 | + int rc; | |
| 579 | + | |
| 580 | + skb = digital_skb_alloc(ddev, 1); | |
| 581 | + if (!skb) | |
| 582 | + return -ENOMEM; | |
| 583 | + | |
| 584 | + skb_push(skb, sizeof(struct digital_dep_req_res)); | |
| 585 | + | |
| 586 | + dep_req = (struct digital_dep_req_res *)skb->data; | |
| 587 | + | |
| 588 | + dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; | |
| 589 | + dep_req->cmd = DIGITAL_CMD_DEP_REQ; | |
| 590 | + dep_req->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU; | |
| 591 | + | |
| 592 | + digital_skb_push_dep_sod(ddev, skb); | |
| 593 | + | |
| 594 | + ddev->skb_add_crc(skb); | |
| 595 | + | |
| 596 | + rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, | |
| 597 | + data_exch); | |
| 598 | + if (rc) | |
| 599 | + kfree_skb(skb); | |
| 600 | + | |
| 601 | + return rc; | |
| 330 | 602 | } |
| 331 | 603 | |
| 332 | 604 | static int digital_in_send_rtox(struct nfc_digital_dev *ddev, |
| @@ -355,12 +627,30 @@ static int digital_in_send_rtox(struct nfc_digital_dev *ddev, · 22 unmodified lines | ||
| 355 | 627 | |
| 356 | 628 | ddev->skb_add_crc(skb); |
| 357 | 629 | |
| 630 | + ddev->saved_skb = skb_get(skb); | |
| 631 | + ddev->saved_skb_len = skb->len; | |
| 632 | + | |
| 358 | 633 | rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, |
| 359 | 634 | data_exch); |
| 635 | + if (rc) { | |
| 636 | + kfree_skb(skb); | |
| 637 | + kfree_skb(ddev->saved_skb); | |
| 638 | + ddev->saved_skb = NULL; | |
| 639 | + } | |
| 360 | 640 | |
| 361 | 641 | return rc; |
| 362 | 642 | } |
| 363 | 643 | |
| 644 | +static int digital_in_send_saved_skb(struct nfc_digital_dev *ddev, | |
| 645 | + struct digital_data_exch *data_exch) | |
| 646 | +{ | |
| 647 | + skb_get(ddev->saved_skb); | |
| 648 | + skb_push(ddev->saved_skb, ddev->saved_skb_len); | |
| 649 | + | |
| 650 | + return digital_in_send_cmd(ddev, ddev->saved_skb, 1500, | |
| 651 | + digital_in_recv_dep_res, data_exch); | |
| 652 | +} | |
| 653 | + | |
| 364 | 654 | static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, |
| 365 | 655 | struct sk_buff *resp) |
| 366 | 656 | { |
| @@ -373,25 +663,67 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, · 6 unmodified lines | ||
| 373 | 663 | if (IS_ERR(resp)) { |
| 374 | 664 | rc = PTR_ERR(resp); |
| 375 | 665 | resp = NULL; |
| 666 | + | |
| 667 | + if (((rc != -ETIMEDOUT) || ddev->nack_count) && | |
| 668 | + (ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) { | |
| 669 | + ddev->atn_count = 0; | |
| 670 | + | |
| 671 | + rc = digital_in_send_nack(ddev, data_exch); | |
| 672 | + if (rc) | |
| 673 | + goto error; | |
| 674 | + | |
| 675 | + return; | |
| 676 | + } else if ((rc == -ETIMEDOUT) && | |
| 677 | + (ddev->atn_count++ < DIGITAL_NFC_DEP_N_RETRY_ATN)) { | |
| 678 | + ddev->nack_count = 0; | |
| 679 | + | |
| 680 | + rc = digital_in_send_atn(ddev, data_exch); | |
| 681 | + if (rc) | |
| 682 | + goto error; | |
| 683 | + | |
| 684 | + return; | |
| 685 | + } | |
| 686 | + | |
| 687 | + goto exit; | |
| 688 | + } | |
| 689 | + | |
| 690 | + rc = digital_skb_pull_dep_sod(ddev, resp); | |
| 691 | + if (rc) { | |
| 692 | + PROTOCOL_ERR("14.4.1.2"); | |
| 376 | 693 | goto exit; |
| 377 | 694 | } |
| 378 | 695 | |
| 379 | 696 | rc = ddev->skb_check_crc(resp); |
| 380 | 697 | if (rc) { |
| 698 | + if ((resp->len >= 4) && | |
| 699 | + (ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) { | |
| 700 | + ddev->atn_count = 0; | |
| 701 | + | |
| 702 | + rc = digital_in_send_nack(ddev, data_exch); | |
| 703 | + if (rc) | |
| 704 | + goto error; | |
| 705 | + | |
| 706 | + kfree_skb(resp); | |
| 707 | + | |
| 708 | + return; | |
| 709 | + } | |
| 710 | + | |
| 381 | 711 | PROTOCOL_ERR("14.4.1.6"); |
| 382 | 712 | goto error; |
| 383 | 713 | } |
| 384 | 714 | |
| 385 | − rc = digital_skb_pull_dep_sod(ddev, resp); | |
| 386 | − if (rc) { | |
| 387 | − PROTOCOL_ERR("14.4.1.2"); | |
| 715 | + ddev->atn_count = 0; | |
| 716 | + ddev->nack_count = 0; | |
| 717 | + | |
| 718 | + if (resp->len > ddev->local_payload_max) { | |
| 719 | + rc = -EMSGSIZE; | |
| 388 | 720 | goto exit; |
| 389 | 721 | } |
| 390 | 722 | |
| 723 | + size = sizeof(struct digital_dep_req_res); | |
| 391 | 724 | dep_res = (struct digital_dep_req_res *)resp->data; |
| 392 | 725 | |
| 393 | − if (resp->len < sizeof(struct digital_dep_req_res) || | |
| 394 | − dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN || | |
| 726 | + if (resp->len < size || dep_res->dir != DIGITAL_NFC_DEP_FRAME_DIR_IN || | |
| 395 | 727 | dep_res->cmd != DIGITAL_CMD_DEP_RES) { |
| 396 | 728 | rc = -EIO; |
| 397 | 729 | goto error; |
| @@ -399,6 +731,24 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, · 1 unmodified line | ||
| 399 | 731 | |
| 400 | 732 | pfb = dep_res->pfb; |
| 401 | 733 | |
| 734 | + if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) { | |
| 735 | + PROTOCOL_ERR("14.8.2.1"); | |
| 736 | + rc = -EIO; | |
| 737 | + goto error; | |
| 738 | + } | |
| 739 | + | |
| 740 | + if (DIGITAL_NFC_DEP_NAD_BIT_SET(pfb)) { | |
| 741 | + rc = -EIO; | |
| 742 | + goto exit; | |
| 743 | + } | |
| 744 | + | |
| 745 | + if (size > resp->len) { | |
| 746 | + rc = -EIO; | |
| 747 | + goto error; | |
| 748 | + } | |
| 749 | + | |
| 750 | + skb_pull(resp, size); | |
| 751 | + | |
| 402 | 752 | switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { |
| 403 | 753 | case DIGITAL_NFC_DEP_PFB_I_PDU: |
| 404 | 754 | if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { |
| @@ -409,21 +759,71 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, · 4 unmodified lines | ||
| 409 | 759 | |
| 410 | 760 | ddev->curr_nfc_dep_pni = |
| 411 | 761 | DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); |
| 762 | + | |
| 763 | + kfree_skb(ddev->saved_skb); | |
| 764 | + ddev->saved_skb = NULL; | |
| 765 | + | |
| 766 | + resp = digital_recv_dep_data_gather(ddev, pfb, resp, | |
| 767 | + digital_in_send_ack, | |
| 768 | + data_exch); | |
| 769 | + if (IS_ERR(resp)) { | |
| 770 | + rc = PTR_ERR(resp); | |
| 771 | + resp = NULL; | |
| 772 | + goto error; | |
| 773 | + } | |
| 774 | + | |
| 775 | + /* If resp is NULL then we're still chaining so return and | |
| 776 | + * wait for the next part of the PDU. Else, the PDU is | |
| 777 | + * complete so pass it up. | |
| 778 | + */ | |
| 779 | + if (!resp) | |
| 780 | + return; | |
| 781 | + | |
| 412 | 782 | rc = 0; |
| 413 | 783 | break; |
| 414 | 784 | |
| 415 | 785 | case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: |
| 786 | + if (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni) { | |
| 787 | + PROTOCOL_ERR("14.12.3.3"); | |
| 788 | + rc = -EIO; | |
| 789 | + goto exit; | |
| 790 | + } | |
| 791 | + | |
| 792 | + ddev->curr_nfc_dep_pni = | |
| 793 | + DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); | |
| 794 | + | |
| 795 | + if (ddev->chaining_skb && !DIGITAL_NFC_DEP_NACK_BIT_SET(pfb)) { | |
| 796 | + kfree_skb(ddev->saved_skb); | |
| 797 | + ddev->saved_skb = NULL; | |
| 798 | + | |
| 799 | + rc = digital_in_send_dep_req(ddev, NULL, | |
| 800 | + ddev->chaining_skb, | |
| 801 | + ddev->data_exch); | |
| 802 | + if (rc) | |
| 803 | + goto error; | |
| 804 | + | |
| 805 | + return; | |
| 806 | + } | |
| 807 | + | |
| 416 | 808 | pr_err("Received a ACK/NACK PDU\n"); |
| 417 | − rc = -EIO; | |
| 418 | − goto error; | |
| 809 | + rc = -EINVAL; | |
| 810 | + goto exit; | |
| 419 | 811 | |
| 420 | 812 | case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: |
| 421 | − if (!DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { | |
| 422 | − rc = -EINVAL; | |
| 423 | − goto error; | |
| 813 | + if (!DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { /* ATN */ | |
| 814 | + rc = digital_in_send_saved_skb(ddev, data_exch); | |
| 815 | + if (rc) { | |
| 816 | + kfree_skb(ddev->saved_skb); | |
| 817 | + goto error; | |
| 818 | + } | |
| 819 | + | |
| 820 | + return; | |
| 424 | 821 | } |
| 425 | 822 | |
| 426 | − rc = digital_in_send_rtox(ddev, data_exch, resp->data[3]); | |
| 823 | + kfree_skb(ddev->saved_skb); | |
| 824 | + ddev->saved_skb = NULL; | |
| 825 | + | |
| 826 | + rc = digital_in_send_rtox(ddev, data_exch, resp->data[0]); | |
| 427 | 827 | if (rc) |
| 428 | 828 | goto error; |
| 429 | 829 | |
| @@ -431,30 +831,18 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, · 1 unmodified line | ||
| 431 | 831 | return; |
| 432 | 832 | } |
| 433 | 833 | |
| 434 | − if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb)) { | |
| 435 | − pr_err("MI bit set. Chained PDU not supported\n"); | |
| 436 | − rc = -EIO; | |
| 437 | − goto error; | |
| 438 | − } | |
| 439 | − | |
| 440 | − size = sizeof(struct digital_dep_req_res); | |
| 441 | − | |
| 442 | − if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) | |
| 443 | − size++; | |
| 444 | − | |
| 445 | − if (size > resp->len) { | |
| 446 | − rc = -EIO; | |
| 447 | − goto error; | |
| 448 | − } | |
| 449 | − | |
| 450 | − skb_pull(resp, size); | |
| 451 | − | |
| 452 | 834 | exit: |
| 453 | 835 | data_exch->cb(data_exch->cb_context, resp, rc); |
| 454 | 836 | |
| 455 | 837 | error: |
| 456 | 838 | kfree(data_exch); |
| 457 | 839 | |
| 840 | + kfree_skb(ddev->chaining_skb); | |
| 841 | + ddev->chaining_skb = NULL; | |
| 842 | + | |
| 843 | + kfree_skb(ddev->saved_skb); | |
| 844 | + ddev->saved_skb = NULL; | |
| 845 | + | |
| 458 | 846 | if (rc) |
| 459 | 847 | kfree_skb(resp); |
| 460 | 848 | } |
| @@ -464,20 +852,47 @@ int digital_in_send_dep_req(struct nfc_digital_dev *ddev, · 3 unmodified lines | ||
| 464 | 852 | struct digital_data_exch *data_exch) |
| 465 | 853 | { |
| 466 | 854 | struct digital_dep_req_res *dep_req; |
| 855 | + struct sk_buff *chaining_skb, *tmp_skb; | |
| 856 | + int rc; | |
| 467 | 857 | |
| 468 | 858 | skb_push(skb, sizeof(struct digital_dep_req_res)); |
| 469 | 859 | |
| 470 | 860 | dep_req = (struct digital_dep_req_res *)skb->data; |
| 861 | + | |
| 471 | 862 | dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT; |
| 472 | 863 | dep_req->cmd = DIGITAL_CMD_DEP_REQ; |
| 473 | 864 | dep_req->pfb = ddev->curr_nfc_dep_pni; |
| 474 | 865 | |
| 475 | − digital_skb_push_dep_sod(ddev, skb); | |
| 866 | + ddev->atn_count = 0; | |
| 867 | + ddev->nack_count = 0; | |
| 476 | 868 | |
| 477 | − ddev->skb_add_crc(skb); | |
| 869 | + chaining_skb = ddev->chaining_skb; | |
| 870 | + | |
| 871 | + tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_req, data_exch); | |
| 872 | + if (IS_ERR(tmp_skb)) | |
| 873 | + return PTR_ERR(tmp_skb); | |
| 874 | + | |
| 875 | + digital_skb_push_dep_sod(ddev, tmp_skb); | |
| 876 | + | |
| 877 | + ddev->skb_add_crc(tmp_skb); | |
| 478 | 878 | |
| 479 | − return digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res, | |
| 480 | − data_exch); | |
| 879 | + ddev->saved_skb = skb_get(tmp_skb); | |
| 880 | + ddev->saved_skb_len = tmp_skb->len; | |
| 881 | + | |
| 882 | + rc = digital_in_send_cmd(ddev, tmp_skb, 1500, digital_in_recv_dep_res, | |
| 883 | + data_exch); | |
| 884 | + if (rc) { | |
| 885 | + if (tmp_skb != skb) | |
| 886 | + kfree_skb(tmp_skb); | |
| 887 | + | |
| 888 | + kfree_skb(chaining_skb); | |
| 889 | + ddev->chaining_skb = NULL; | |
| 890 | + | |
| 891 | + kfree_skb(ddev->saved_skb); | |
| 892 | + ddev->saved_skb = NULL; | |
| 893 | + } | |
| 894 | + | |
| 895 | + return rc; | |
| 481 | 896 | } |
| 482 | 897 | |
| 483 | 898 | static void digital_tg_set_rf_tech(struct nfc_digital_dev *ddev, u8 rf_tech) |
| @@ -507,11 +922,106 @@ static void digital_tg_set_rf_tech(struct nfc_digital_dev *ddev, u8 rf_tech) · 23 unmodified lines | ||
| 507 | 922 | } |
| 508 | 923 | } |
| 509 | 924 | |
| 925 | +static int digital_tg_send_ack(struct nfc_digital_dev *ddev, | |
| 926 | + struct digital_data_exch *data_exch) | |
| 927 | +{ | |
| 928 | + struct digital_dep_req_res *dep_res; | |
| 929 | + struct sk_buff *skb; | |
| 930 | + int rc; | |
| 931 | + | |
| 932 | + skb = digital_skb_alloc(ddev, 1); | |
| 933 | + if (!skb) | |
| 934 | + return -ENOMEM; | |
| 935 | + | |
| 936 | + skb_push(skb, sizeof(struct digital_dep_req_res)); | |
| 937 | + | |
| 938 | + dep_res = (struct digital_dep_req_res *)skb->data; | |
| 939 | + | |
| 940 | + dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; | |
| 941 | + dep_res->cmd = DIGITAL_CMD_DEP_RES; | |
| 942 | + dep_res->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU | | |
| 943 | + ddev->curr_nfc_dep_pni; | |
| 944 | + | |
| 945 | + if (ddev->did) { | |
| 946 | + dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; | |
| 947 | + | |
| 948 | + memcpy(skb_put(skb, sizeof(ddev->did)), &ddev->did, | |
| 949 | + sizeof(ddev->did)); | |
| 950 | + } | |
| 951 | + | |
| 952 | + ddev->curr_nfc_dep_pni = | |
| 953 | + DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); | |
| 954 | + | |
| 955 | + digital_skb_push_dep_sod(ddev, skb); | |
| 956 | + | |
| 957 | + ddev->skb_add_crc(skb); | |
| 958 | + | |
| 959 | + ddev->saved_skb = skb_get(skb); | |
| 960 | + ddev->saved_skb_len = skb->len; | |
| 961 | + | |
| 962 | + rc = digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, | |
| 963 | + data_exch); | |
| 964 | + if (rc) { | |
| 965 | + kfree_skb(skb); | |
| 966 | + kfree_skb(ddev->saved_skb); | |
| 967 | + ddev->saved_skb = NULL; | |
| 968 | + } | |
| 969 | + | |
| 970 | + return rc; | |
| 971 | +} | |
| 972 | + | |
| 973 | +static int digital_tg_send_atn(struct nfc_digital_dev *ddev) | |
| 974 | +{ | |
| 975 | + struct digital_dep_req_res *dep_res; | |
| 976 | + struct sk_buff *skb; | |
| 977 | + int rc; | |
| 978 | + | |
| 979 | + skb = digital_skb_alloc(ddev, 1); | |
| 980 | + if (!skb) | |
| 981 | + return -ENOMEM; | |
| 982 | + | |
| 983 | + skb_push(skb, sizeof(struct digital_dep_req_res)); | |
| 984 | + | |
| 985 | + dep_res = (struct digital_dep_req_res *)skb->data; | |
| 986 | + | |
| 987 | + dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; | |
| 988 | + dep_res->cmd = DIGITAL_CMD_DEP_RES; | |
| 989 | + dep_res->pfb = DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU; | |
| 990 | + | |
| 991 | + if (ddev->did) { | |
| 992 | + dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; | |
| 993 | + | |
| 994 | + memcpy(skb_put(skb, sizeof(ddev->did)), &ddev->did, | |
| 995 | + sizeof(ddev->did)); | |
| 996 | + } | |
| 997 | + | |
| 998 | + digital_skb_push_dep_sod(ddev, skb); | |
| 999 | + | |
| 1000 | + ddev->skb_add_crc(skb); | |
| 1001 | + | |
| 1002 | + rc = digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, | |
| 1003 | + NULL); | |
| 1004 | + if (rc) | |
| 1005 | + kfree_skb(skb); | |
| 1006 | + | |
| 1007 | + return rc; | |
| 1008 | +} | |
| 1009 | + | |
| 1010 | +static int digital_tg_send_saved_skb(struct nfc_digital_dev *ddev) | |
| 1011 | +{ | |
| 1012 | + skb_get(ddev->saved_skb); | |
| 1013 | + skb_push(ddev->saved_skb, ddev->saved_skb_len); | |
| 1014 | + | |
| 1015 | + return digital_tg_send_cmd(ddev, ddev->saved_skb, 1500, | |
| 1016 | + digital_tg_recv_dep_req, NULL); | |
| 1017 | +} | |
| 1018 | + | |
| 510 | 1019 | static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, |
| 511 | 1020 | struct sk_buff *resp) |
| 512 | 1021 | { |
| 513 | 1022 | int rc; |
| 514 | 1023 | struct digital_dep_req_res *dep_req; |
| 1024 | + u8 pfb; | |
| 515 | 1025 | size_t size; |
| 516 | 1026 | |
| 517 | 1027 | if (IS_ERR(resp)) { |
| @@ -532,6 +1042,11 @@ static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, · 14 unmodified lines | ||
| 532 | 1042 | goto exit; |
| 533 | 1043 | } |
| 534 | 1044 | |
| 1045 | + if (resp->len > ddev->local_payload_max) { | |
| 1046 | + rc = -EMSGSIZE; | |
| 1047 | + goto exit; | |
| 1048 | + } | |
| 1049 | + | |
| 535 | 1050 | size = sizeof(struct digital_dep_req_res); |
| 536 | 1051 | dep_req = (struct digital_dep_req_res *)resp->data; |
| 537 | 1052 | |
| @@ -541,34 +1056,147 @@ static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, · 3 unmodified lines | ||
| 541 | 1056 | goto exit; |
| 542 | 1057 | } |
| 543 | 1058 | |
| 544 | − if (DIGITAL_NFC_DEP_DID_BIT_SET(dep_req->pfb)) | |
| 545 | − size++; | |
| 1059 | + pfb = dep_req->pfb; | |
| 546 | 1060 | |
| 547 | − if (resp->len < size) { | |
| 1061 | + if (DIGITAL_NFC_DEP_DID_BIT_SET(pfb)) { | |
| 1062 | + if (ddev->did && (ddev->did == resp->data[3])) { | |
| 1063 | + size++; | |
| 1064 | + } else { | |
| 1065 | + rc = -EIO; | |
| 1066 | + goto exit; | |
| 1067 | + } | |
| 1068 | + } else if (ddev->did) { | |
| 548 | 1069 | rc = -EIO; |
| 549 | 1070 | goto exit; |
| 550 | 1071 | } |
| 551 | 1072 | |
| 552 | − switch (DIGITAL_NFC_DEP_PFB_TYPE(dep_req->pfb)) { | |
| 1073 | + if (DIGITAL_NFC_DEP_NAD_BIT_SET(pfb)) { | |
| 1074 | + rc = -EIO; | |
| 1075 | + goto exit; | |
| 1076 | + } | |
| 1077 | + | |
| 1078 | + if (size > resp->len) { | |
| 1079 | + rc = -EIO; | |
| 1080 | + goto exit; | |
| 1081 | + } | |
| 1082 | + | |
| 1083 | + skb_pull(resp, size); | |
| 1084 | + | |
| 1085 | + switch (DIGITAL_NFC_DEP_PFB_TYPE(pfb)) { | |
| 553 | 1086 | case DIGITAL_NFC_DEP_PFB_I_PDU: |
| 554 | 1087 | pr_debug("DIGITAL_NFC_DEP_PFB_I_PDU\n"); |
| 555 | − ddev->curr_nfc_dep_pni = DIGITAL_NFC_DEP_PFB_PNI(dep_req->pfb); | |
| 1088 | + | |
| 1089 | + if ((ddev->atn_count && (DIGITAL_NFC_DEP_PFB_PNI(pfb - 1) != | |
| 1090 | + ddev->curr_nfc_dep_pni)) || | |
| 1091 | + (DIGITAL_NFC_DEP_PFB_PNI(pfb) != ddev->curr_nfc_dep_pni)) { | |
| 1092 | + PROTOCOL_ERR("14.12.3.4"); | |
| 1093 | + rc = -EIO; | |
| 1094 | + goto exit; | |
| 1095 | + } | |
| 1096 | + | |
| 1097 | + if (ddev->atn_count) { | |
| 1098 | + ddev->atn_count = 0; | |
| 1099 | + | |
| 1100 | + rc = digital_tg_send_saved_skb(ddev); | |
| 1101 | + if (rc) | |
| 1102 | + goto exit; | |
| 1103 | + | |
| 1104 | + return; | |
| 1105 | + } | |
| 1106 | + | |
| 1107 | + kfree_skb(ddev->saved_skb); | |
| 1108 | + ddev->saved_skb = NULL; | |
| 1109 | + | |
| 1110 | + resp = digital_recv_dep_data_gather(ddev, pfb, resp, | |
| 1111 | + digital_tg_send_ack, NULL); | |
| 1112 | + if (IS_ERR(resp)) { | |
| 1113 | + rc = PTR_ERR(resp); | |
| 1114 | + resp = NULL; | |
| 1115 | + goto exit; | |
| 1116 | + } | |
| 1117 | + | |
| 1118 | + /* If resp is NULL then we're still chaining so return and | |
| 1119 | + * wait for the next part of the PDU. Else, the PDU is | |
| 1120 | + * complete so pass it up. | |
| 1121 | + */ | |
| 1122 | + if (!resp) | |
| 1123 | + return; | |
| 1124 | + | |
| 1125 | + rc = 0; | |
| 556 | 1126 | break; |
| 557 | 1127 | case DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU: |
| 558 | − pr_err("Received a ACK/NACK PDU\n"); | |
| 559 | − rc = -EINVAL; | |
| 560 | − goto exit; | |
| 1128 | + if (!DIGITAL_NFC_DEP_NACK_BIT_SET(pfb)) { /* ACK */ | |
| 1129 | + if ((ddev->atn_count && | |
| 1130 | + (DIGITAL_NFC_DEP_PFB_PNI(pfb - 1) != | |
| 1131 | + ddev->curr_nfc_dep_pni)) || | |
| 1132 | + (DIGITAL_NFC_DEP_PFB_PNI(pfb) != | |
| 1133 | + ddev->curr_nfc_dep_pni) || | |
| 1134 | + !ddev->chaining_skb || !ddev->saved_skb) { | |
| 1135 | + rc = -EIO; | |
| 1136 | + goto exit; | |
| 1137 | + } | |
| 1138 | + | |
| 1139 | + if (ddev->atn_count) { | |
| 1140 | + ddev->atn_count = 0; | |
| 1141 | + | |
| 1142 | + rc = digital_tg_send_saved_skb(ddev); | |
| 1143 | + if (rc) | |
| 1144 | + goto exit; | |
| 1145 | + | |
| 1146 | + return; | |
| 1147 | + } | |
| 1148 | + | |
| 1149 | + kfree_skb(ddev->saved_skb); | |
| 1150 | + ddev->saved_skb = NULL; | |
| 1151 | + | |
| 1152 | + rc = digital_tg_send_dep_res(ddev, ddev->chaining_skb); | |
| 1153 | + if (rc) | |
| 1154 | + goto exit; | |
| 1155 | + } else { /* NACK */ | |
| 1156 | + if ((DIGITAL_NFC_DEP_PFB_PNI(pfb + 1) != | |
| 1157 | + ddev->curr_nfc_dep_pni) || | |
| 1158 | + !ddev->saved_skb) { | |
| 1159 | + rc = -EIO; | |
| 1160 | + goto exit; | |
| 1161 | + } | |
| 1162 | + | |
| 1163 | + ddev->atn_count = 0; | |
| 1164 | + | |
| 1165 | + rc = digital_tg_send_saved_skb(ddev); | |
| 1166 | + if (rc) { | |
| 1167 | + kfree_skb(ddev->saved_skb); | |
| 1168 | + goto exit; | |
| 1169 | + } | |
| 1170 | + } | |
| 1171 | + | |
| 1172 | + return; | |
| 561 | 1173 | case DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU: |
| 562 | − pr_err("Received a SUPERVISOR PDU\n"); | |
| 563 | − rc = -EINVAL; | |
| 564 | − goto exit; | |
| 565 | − } | |
| 1174 | + if (DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb)) { | |
| 1175 | + rc = -EINVAL; | |
| 1176 | + goto exit; | |
| 1177 | + } | |
| 566 | 1178 | |
| 567 | − skb_pull(resp, size); | |
| 1179 | + rc = digital_tg_send_atn(ddev); | |
| 1180 | + if (rc) | |
| 1181 | + goto exit; | |
| 1182 | + | |
| 1183 | + ddev->atn_count++; | |
| 1184 | + | |
| 1185 | + kfree_skb(resp); | |
| 1186 | + return; | |
| 1187 | + } | |
| 568 | 1188 | |
| 569 | 1189 | rc = nfc_tm_data_received(ddev->nfc_dev, resp); |
| 570 | 1190 | |
| 571 | 1191 | exit: |
| 1192 | + kfree_skb(ddev->chaining_skb); | |
| 1193 | + ddev->chaining_skb = NULL; | |
| 1194 | + | |
| 1195 | + ddev->atn_count = 0; | |
| 1196 | + | |
| 1197 | + kfree_skb(ddev->saved_skb); | |
| 1198 | + ddev->saved_skb = NULL; | |
| 1199 | + | |
| 572 | 1200 | if (rc) |
| 573 | 1201 | kfree_skb(resp); |
| 574 | 1202 | } |
| @@ -576,20 +1204,54 @@ exit: · 1 unmodified line | ||
| 576 | 1204 | int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb) |
| 577 | 1205 | { |
| 578 | 1206 | struct digital_dep_req_res *dep_res; |
| 1207 | + struct sk_buff *chaining_skb, *tmp_skb; | |
| 1208 | + int rc; | |
| 579 | 1209 | |
| 580 | 1210 | skb_push(skb, sizeof(struct digital_dep_req_res)); |
| 1211 | + | |
| 581 | 1212 | dep_res = (struct digital_dep_req_res *)skb->data; |
| 582 | 1213 | |
| 583 | 1214 | dep_res->dir = DIGITAL_NFC_DEP_FRAME_DIR_IN; |
| 584 | 1215 | dep_res->cmd = DIGITAL_CMD_DEP_RES; |
| 585 | 1216 | dep_res->pfb = ddev->curr_nfc_dep_pni; |
| 586 | 1217 | |
| 587 | − digital_skb_push_dep_sod(ddev, skb); | |
| 1218 | + if (ddev->did) { | |
| 1219 | + dep_res->pfb |= DIGITAL_NFC_DEP_PFB_DID_BIT; | |
| 588 | 1220 | |
| 589 | − ddev->skb_add_crc(skb); | |
| 1221 | + memcpy(skb_put(skb, sizeof(ddev->did)), &ddev->did, | |
| 1222 | + sizeof(ddev->did)); | |
| 1223 | + } | |
| 1224 | + | |
| 1225 | + ddev->curr_nfc_dep_pni = | |
| 1226 | + DIGITAL_NFC_DEP_PFB_PNI(ddev->curr_nfc_dep_pni + 1); | |
| 1227 | + | |
| 1228 | + chaining_skb = ddev->chaining_skb; | |
| 1229 | + | |
| 1230 | + tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_res, NULL); | |
| 1231 | + if (IS_ERR(tmp_skb)) | |
| 1232 | + return PTR_ERR(tmp_skb); | |
| 1233 | + | |
| 1234 | + digital_skb_push_dep_sod(ddev, tmp_skb); | |
| 1235 | + | |
| 1236 | + ddev->skb_add_crc(tmp_skb); | |
| 1237 | + | |
| 1238 | + ddev->saved_skb = skb_get(tmp_skb); | |
| 1239 | + ddev->saved_skb_len = tmp_skb->len; | |
| 1240 | + | |
| 1241 | + rc = digital_tg_send_cmd(ddev, tmp_skb, 1500, digital_tg_recv_dep_req, | |
| 1242 | + NULL); | |
| 1243 | + if (rc) { | |
| 1244 | + if (tmp_skb != skb) | |
| 1245 | + kfree_skb(tmp_skb); | |
| 1246 | + | |
| 1247 | + kfree_skb(chaining_skb); | |
| 1248 | + ddev->chaining_skb = NULL; | |
| 590 | 1249 | |
| 591 | − return digital_tg_send_cmd(ddev, skb, 1500, digital_tg_recv_dep_req, | |
| 592 | − NULL); | |
| 1250 | + kfree_skb(ddev->saved_skb); | |
| 1251 | + ddev->saved_skb = NULL; | |
| 1252 | + } | |
| 1253 | + | |
| 1254 | + return rc; | |
| 593 | 1255 | } |
| 594 | 1256 | |
| 595 | 1257 | static void digital_tg_send_psl_res_complete(struct nfc_digital_dev *ddev, |
| @@ -632,9 +1294,10 @@ static int digital_tg_send_psl_res(struct nfc_digital_dev *ddev, u8 did, · 36 unmodified lines | ||
| 632 | 1294 | |
| 633 | 1295 | ddev->skb_add_crc(skb); |
| 634 | 1296 | |
| 1297 | + ddev->curr_nfc_dep_pni = 0; | |
| 1298 | + | |
| 635 | 1299 | rc = digital_tg_send_cmd(ddev, skb, 0, digital_tg_send_psl_res_complete, |
| 636 | 1300 | (void *)(unsigned long)rf_tech); |
| 637 | − | |
| 638 | 1301 | if (rc) |
| 639 | 1302 | kfree_skb(skb); |
| 640 | 1303 | |
| @@ -647,7 +1310,7 @@ static void digital_tg_recv_psl_req(struct nfc_digital_dev *ddev, void *arg, · 6 unmodified lines | ||
| 647 | 1310 | int rc; |
| 648 | 1311 | struct digital_psl_req *psl_req; |
| 649 | 1312 | u8 rf_tech; |
| 650 | − u8 dsi; | |
| 1313 | + u8 dsi, payload_size, payload_bits; | |
| 651 | 1314 | |
| 652 | 1315 | if (IS_ERR(resp)) { |
| 653 | 1316 | rc = PTR_ERR(resp); |
| @@ -692,6 +1355,18 @@ static void digital_tg_recv_psl_req(struct nfc_digital_dev *ddev, void *arg, · 38 unmodified lines | ||
| 692 | 1355 | goto exit; |
| 693 | 1356 | } |
| 694 | 1357 | |
| 1358 | + payload_bits = DIGITAL_PAYLOAD_FSL_TO_BITS(psl_req->fsl); | |
| 1359 | + payload_size = digital_payload_bits_to_size(payload_bits); | |
| 1360 | + | |
| 1361 | + if (!payload_size || (payload_size > min(ddev->local_payload_max, | |
| 1362 | + ddev->remote_payload_max))) { | |
| 1363 | + rc = -EINVAL; | |
| 1364 | + goto exit; | |
| 1365 | + } | |
| 1366 | + | |
| 1367 | + ddev->local_payload_max = payload_size; | |
| 1368 | + ddev->remote_payload_max = payload_size; | |
| 1369 | + | |
| 695 | 1370 | rc = digital_tg_send_psl_res(ddev, psl_req->did, rf_tech); |
| 696 | 1371 | |
| 697 | 1372 | exit: |
| @@ -712,6 +1387,8 @@ static void digital_tg_send_atr_res_complete(struct nfc_digital_dev *ddev, · 14 unmodified lines | ||
| 712 | 1387 | if (resp->data[0] == DIGITAL_NFC_DEP_NFCA_SOD_SB) |
| 713 | 1388 | offset++; |
| 714 | 1389 | |
| 1390 | + ddev->atn_count = 0; | |
| 1391 | + | |
| 715 | 1392 | if (resp->data[offset] == DIGITAL_CMD_PSL_REQ) |
| 716 | 1393 | digital_tg_recv_psl_req(ddev, arg, resp); |
| 717 | 1394 | else |
| @@ -723,7 +1400,7 @@ static int digital_tg_send_atr_res(struct nfc_digital_dev *ddev, · 5 unmodified lines | ||
| 723 | 1400 | { |
| 724 | 1401 | struct digital_atr_res *atr_res; |
| 725 | 1402 | struct sk_buff *skb; |
| 726 | − u8 *gb; | |
| 1403 | + u8 *gb, payload_bits; | |
| 727 | 1404 | size_t gb_len; |
| 728 | 1405 | int rc; |
| 729 | 1406 | |
| @@ -744,7 +1421,11 @@ static int digital_tg_send_atr_res(struct nfc_digital_dev *ddev, · 14 unmodified lines | ||
| 744 | 1421 | atr_res->cmd = DIGITAL_CMD_ATR_RES; |
| 745 | 1422 | memcpy(atr_res->nfcid3, atr_req->nfcid3, sizeof(atr_req->nfcid3)); |
| 746 | 1423 | atr_res->to = 8; |
| 747 | − atr_res->pp = DIGITAL_LR_BITS_PAYLOAD_SIZE_254B; | |
| 1424 | + | |
| 1425 | + ddev->local_payload_max = DIGITAL_PAYLOAD_SIZE_MAX; | |
| 1426 | + payload_bits = digital_payload_size_to_bits(ddev->local_payload_max); | |
| 1427 | + atr_res->pp = DIGITAL_PAYLOAD_BITS_TO_PP(payload_bits); | |
| 1428 | + | |
| 748 | 1429 | if (gb_len) { |
| 749 | 1430 | skb_put(skb, gb_len); |
| 750 | 1431 | |
| @@ -756,12 +1437,12 @@ static int digital_tg_send_atr_res(struct nfc_digital_dev *ddev, · 5 unmodified lines | ||
| 756 | 1437 | |
| 757 | 1438 | ddev->skb_add_crc(skb); |
| 758 | 1439 | |
| 1440 | + ddev->curr_nfc_dep_pni = 0; | |
| 1441 | + | |
| 759 | 1442 | rc = digital_tg_send_cmd(ddev, skb, 999, |
| 760 | 1443 | digital_tg_send_atr_res_complete, NULL); |
| 761 | − if (rc) { | |
| 1444 | + if (rc) | |
| 762 | 1445 | kfree_skb(skb); |
| 763 | − return rc; | |
| 764 | − } | |
| 765 | 1446 | |
| 766 | 1447 | return rc; |
| 767 | 1448 | } |
| @@ -772,7 +1453,7 @@ void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg, · 4 unmodified lines | ||
| 772 | 1453 | int rc; |
| 773 | 1454 | struct digital_atr_req *atr_req; |
| 774 | 1455 | size_t gb_len, min_size; |
| 775 | − u8 poll_tech_count; | |
| 1456 | + u8 poll_tech_count, payload_bits; | |
| 776 | 1457 | |
| 777 | 1458 | if (IS_ERR(resp)) { |
| 778 | 1459 | rc = PTR_ERR(resp); |
| @@ -815,11 +1496,22 @@ void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg, · 36 unmodified lines | ||
| 815 | 1496 | atr_req = (struct digital_atr_req *)resp->data; |
| 816 | 1497 | |
| 817 | 1498 | if (atr_req->dir != DIGITAL_NFC_DEP_FRAME_DIR_OUT || |
| 818 | − atr_req->cmd != DIGITAL_CMD_ATR_REQ) { | |
| 1499 | + atr_req->cmd != DIGITAL_CMD_ATR_REQ || | |
| 1500 | + atr_req->did > DIGITAL_DID_MAX) { | |
| 819 | 1501 | rc = -EINVAL; |
| 820 | 1502 | goto exit; |
| 821 | 1503 | } |
| 822 | 1504 | |
| 1505 | + payload_bits = DIGITAL_PAYLOAD_PP_TO_BITS(atr_req->pp); | |
| 1506 | + ddev->remote_payload_max = digital_payload_bits_to_size(payload_bits); | |
| 1507 | + | |
| 1508 | + if (!ddev->remote_payload_max) { | |
| 1509 | + rc = -EINVAL; | |
| 1510 | + goto exit; | |
| 1511 | + } | |
| 1512 | + | |
| 1513 | + ddev->did = atr_req->did; | |
| 1514 | + | |
| 823 | 1515 | rc = digital_tg_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, |
| 824 | 1516 | NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED); |
| 825 | 1517 | if (rc) |
| @@ -345,6 +345,9 @@ int nfc_hci_connect_gate(struct nfc_hci_dev *hdev, u8 dest_host, u8 dest_gate, · 344 unmodified lines | ||
| 345 | 345 | |
| 346 | 346 | pr_debug("\n"); |
| 347 | 347 | |
| 348 | + if (hdev->gate2pipe[dest_gate] == NFC_HCI_DO_NOT_CREATE_PIPE) | |
| 349 | + return 0; | |
| 350 | + | |
| 348 | 351 | if (hdev->gate2pipe[dest_gate] != NFC_HCI_INVALID_PIPE) |
| 349 | 352 | return -EADDRINUSE; |
| 350 | 353 | |
| @@ -167,6 +167,48 @@ exit: · 166 unmodified lines | ||
| 167 | 167 | void nfc_hci_cmd_received(struct nfc_hci_dev *hdev, u8 pipe, u8 cmd, |
| 168 | 168 | struct sk_buff *skb) |
| 169 | 169 | { |
| 170 | + int r = 0; | |
| 171 | + u8 gate = nfc_hci_pipe2gate(hdev, pipe); | |
| 172 | + u8 local_gate, new_pipe; | |
| 173 | + u8 gate_opened = 0x00; | |
| 174 | + | |
| 175 | + pr_debug("from gate %x pipe %x cmd %x\n", gate, pipe, cmd); | |
| 176 | + | |
| 177 | + switch (cmd) { | |
| 178 | + case NFC_HCI_ADM_NOTIFY_PIPE_CREATED: | |
| 179 | + if (skb->len != 5) { | |
| 180 | + r = -EPROTO; | |
| 181 | + break; | |
| 182 | + } | |
| 183 | + | |
| 184 | + local_gate = skb->data[3]; | |
| 185 | + new_pipe = skb->data[4]; | |
| 186 | + nfc_hci_send_response(hdev, gate, NFC_HCI_ANY_OK, NULL, 0); | |
| 187 | + | |
| 188 | + /* save the new created pipe and bind with local gate, | |
| 189 | + * the description for skb->data[3] is destination gate id | |
| 190 | + * but since we received this cmd from host controller, we | |
| 191 | + * are the destination and it is our local gate | |
| 192 | + */ | |
| 193 | + hdev->gate2pipe[local_gate] = new_pipe; | |
| 194 | + break; | |
| 195 | + case NFC_HCI_ANY_OPEN_PIPE: | |
| 196 | + /* if the pipe is already created, we allow remote host to | |
| 197 | + * open it | |
| 198 | + */ | |
| 199 | + if (gate != 0xff) | |
| 200 | + nfc_hci_send_response(hdev, gate, NFC_HCI_ANY_OK, | |
| 201 | + &gate_opened, 1); | |
| 202 | + break; | |
| 203 | + case NFC_HCI_ADM_NOTIFY_ALL_PIPE_CLEARED: | |
| 204 | + nfc_hci_send_response(hdev, gate, NFC_HCI_ANY_OK, NULL, 0); | |
| 205 | + break; | |
| 206 | + default: | |
| 207 | + pr_info("Discarded unknown cmd %x to gate %x\n", cmd, gate); | |
| 208 | + r = -EINVAL; | |
| 209 | + break; | |
| 210 | + } | |
| 211 | + | |
| 170 | 212 | kfree_skb(skb); |
| 171 | 213 | } |
| 172 | 214 | |
| @@ -717,6 +759,19 @@ static int hci_disable_se(struct nfc_dev *nfc_dev, u32 se_idx) · 544 unmodified lines | ||
| 717 | 759 | return 0; |
| 718 | 760 | } |
| 719 | 761 | |
| 762 | +static int hci_se_io(struct nfc_dev *nfc_dev, u32 se_idx, | |
| 763 | + u8 *apdu, size_t apdu_length, | |
| 764 | + se_io_cb_t cb, void *cb_context) | |
| 765 | +{ | |
| 766 | + struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev); | |
| 767 | + | |
| 768 | + if (hdev->ops->se_io) | |
| 769 | + return hdev->ops->se_io(hdev, se_idx, apdu, | |
| 770 | + apdu_length, cb, cb_context); | |
| 771 | + | |
| 772 | + return 0; | |
| 773 | +} | |
| 774 | + | |
| 720 | 775 | static void nfc_hci_failure(struct nfc_hci_dev *hdev, int err) |
| 721 | 776 | { |
| 722 | 777 | mutex_lock(&hdev->msg_tx_mutex); |
| @@ -830,6 +885,7 @@ static struct nfc_ops hci_nfc_ops = { · 107 unmodified lines | ||
| 830 | 885 | .discover_se = hci_discover_se, |
| 831 | 886 | .enable_se = hci_enable_se, |
| 832 | 887 | .disable_se = hci_disable_se, |
| 888 | + .se_io = hci_se_io, | |
| 833 | 889 | }; |
| 834 | 890 | |
| 835 | 891 | struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops, |
| @@ -401,7 +401,8 @@ int nfc_llcp_send_connect(struct nfc_llcp_sock *sock) · 400 unmodified lines | ||
| 401 | 401 | u8 *miux_tlv = NULL, miux_tlv_length; |
| 402 | 402 | u8 *rw_tlv = NULL, rw_tlv_length, rw; |
| 403 | 403 | int err; |
| 404 | − u16 size = 0, miux; | |
| 404 | + u16 size = 0; | |
| 405 | + __be16 miux; | |
| 405 | 406 | |
| 406 | 407 | pr_debug("Sending CONNECT\n"); |
| 407 | 408 | |
| @@ -465,7 +466,8 @@ int nfc_llcp_send_cc(struct nfc_llcp_sock *sock) · 57 unmodified lines | ||
| 465 | 466 | u8 *miux_tlv = NULL, miux_tlv_length; |
| 466 | 467 | u8 *rw_tlv = NULL, rw_tlv_length, rw; |
| 467 | 468 | int err; |
| 468 | − u16 size = 0, miux; | |
| 469 | + u16 size = 0; | |
| 470 | + __be16 miux; | |
| 469 | 471 | |
| 470 | 472 | pr_debug("Sending CC\n"); |
| 471 | 473 | |
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | /* |
| 2 | 2 | * Copyright (C) 2011 Intel Corporation. All rights reserved. |
| 3 | + * Copyright (C) 2014 Marvell International Ltd. | |
| 3 | 4 | * |
| 4 | 5 | * This program is free software; you can redistribute it and/or modify |
| 5 | 6 | * it under the terms of the GNU General Public License as published by |
| @@ -1511,8 +1512,10 @@ int nfc_llcp_data_received(struct nfc_dev *dev, struct sk_buff *skb) · 1505 unmodified lines | ||
| 1511 | 1512 | struct nfc_llcp_local *local; |
| 1512 | 1513 | |
| 1513 | 1514 | local = nfc_llcp_find_local(dev); |
| 1514 | − if (local == NULL) | |
| 1515 | + if (local == NULL) { | |
| 1516 | + kfree_skb(skb); | |
| 1515 | 1517 | return -ENODEV; |
| 1518 | + } | |
| 1516 | 1519 | |
| 1517 | 1520 | __nfc_llcp_recv(local, skb); |
| 1518 | 1521 | |
| @@ -524,13 +524,13 @@ static int llcp_sock_getname(struct socket *sock, struct sockaddr *uaddr, · 523 unmodified lines | ||
| 524 | 524 | |
| 525 | 525 | static inline unsigned int llcp_accept_poll(struct sock *parent) |
| 526 | 526 | { |
| 527 | − struct nfc_llcp_sock *llcp_sock, *n, *parent_sock; | |
| 527 | + struct nfc_llcp_sock *llcp_sock, *parent_sock; | |
| 528 | 528 | struct sock *sk; |
| 529 | 529 | |
| 530 | 530 | parent_sock = nfc_llcp_sock(parent); |
| 531 | 531 | |
| 532 | − list_for_each_entry_safe(llcp_sock, n, &parent_sock->accept_queue, | |
| 533 | − accept_queue) { | |
| 532 | + list_for_each_entry(llcp_sock, &parent_sock->accept_queue, | |
| 533 | + accept_queue) { | |
| 534 | 534 | sk = &llcp_sock->sk; |
| 535 | 535 | |
| 536 | 536 | if (sk->sk_state == LLCP_CONNECTED) |
| @@ -3,6 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | * NFC Controller (NFCC) and a Device Host (DH). |
| 4 | 4 | * |
| 5 | 5 | * Copyright (C) 2011 Texas Instruments, Inc. |
| 6 | + * Copyright (C) 2014 Marvell International Ltd. | |
| 6 | 7 | * |
| 7 | 8 | * Written by Ilan Elias <ilane@ti.com> |
| 8 | 9 | * |
| @@ -196,18 +197,24 @@ static void nci_set_config_req(struct nci_dev *ndev, unsigned long opt) · 187 unmodified lines | ||
| 196 | 197 | nci_send_cmd(ndev, NCI_OP_CORE_SET_CONFIG_CMD, (3 + param->len), &cmd); |
| 197 | 198 | } |
| 198 | 199 | |
| 200 | +struct nci_rf_discover_param { | |
| 201 | + __u32 im_protocols; | |
| 202 | + __u32 tm_protocols; | |
| 203 | +}; | |
| 204 | + | |
| 199 | 205 | static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) |
| 200 | 206 | { |
| 207 | + struct nci_rf_discover_param *param = | |
| 208 | + (struct nci_rf_discover_param *)opt; | |
| 201 | 209 | struct nci_rf_disc_cmd cmd; |
| 202 | − __u32 protocols = opt; | |
| 203 | 210 | |
| 204 | 211 | cmd.num_disc_configs = 0; |
| 205 | 212 | |
| 206 | 213 | if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) && |
| 207 | − (protocols & NFC_PROTO_JEWEL_MASK || | |
| 208 | − protocols & NFC_PROTO_MIFARE_MASK || | |
| 209 | − protocols & NFC_PROTO_ISO14443_MASK || | |
| 210 | − protocols & NFC_PROTO_NFC_DEP_MASK)) { | |
| 214 | + (param->im_protocols & NFC_PROTO_JEWEL_MASK || | |
| 215 | + param->im_protocols & NFC_PROTO_MIFARE_MASK || | |
| 216 | + param->im_protocols & NFC_PROTO_ISO14443_MASK || | |
| 217 | + param->im_protocols & NFC_PROTO_NFC_DEP_MASK)) { | |
| 211 | 218 | cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = |
| 212 | 219 | NCI_NFC_A_PASSIVE_POLL_MODE; |
| 213 | 220 | cmd.disc_configs[cmd.num_disc_configs].frequency = 1; |
| @@ -215,7 +222,7 @@ static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) · 1 unmodified line | ||
| 215 | 222 | } |
| 216 | 223 | |
| 217 | 224 | if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) && |
| 218 | − (protocols & NFC_PROTO_ISO14443_B_MASK)) { | |
| 225 | + (param->im_protocols & NFC_PROTO_ISO14443_B_MASK)) { | |
| 219 | 226 | cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = |
| 220 | 227 | NCI_NFC_B_PASSIVE_POLL_MODE; |
| 221 | 228 | cmd.disc_configs[cmd.num_disc_configs].frequency = 1; |
| @@ -223,8 +230,8 @@ static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) · 1 unmodified line | ||
| 223 | 230 | } |
| 224 | 231 | |
| 225 | 232 | if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) && |
| 226 | − (protocols & NFC_PROTO_FELICA_MASK || | |
| 227 | − protocols & NFC_PROTO_NFC_DEP_MASK)) { | |
| 233 | + (param->im_protocols & NFC_PROTO_FELICA_MASK || | |
| 234 | + param->im_protocols & NFC_PROTO_NFC_DEP_MASK)) { | |
| 228 | 235 | cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = |
| 229 | 236 | NCI_NFC_F_PASSIVE_POLL_MODE; |
| 230 | 237 | cmd.disc_configs[cmd.num_disc_configs].frequency = 1; |
| @@ -232,13 +239,25 @@ static void nci_rf_discover_req(struct nci_dev *ndev, unsigned long opt) · 1 unmodified line | ||
| 232 | 239 | } |
| 233 | 240 | |
| 234 | 241 | if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS) && |
| 235 | − (protocols & NFC_PROTO_ISO15693_MASK)) { | |
| 242 | + (param->im_protocols & NFC_PROTO_ISO15693_MASK)) { | |
| 236 | 243 | cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = |
| 237 | 244 | NCI_NFC_V_PASSIVE_POLL_MODE; |
| 238 | 245 | cmd.disc_configs[cmd.num_disc_configs].frequency = 1; |
| 239 | 246 | cmd.num_disc_configs++; |
| 240 | 247 | } |
| 241 | 248 | |
| 249 | + if ((cmd.num_disc_configs < NCI_MAX_NUM_RF_CONFIGS - 1) && | |
| 250 | + (param->tm_protocols & NFC_PROTO_NFC_DEP_MASK)) { | |
| 251 | + cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = | |
| 252 | + NCI_NFC_A_PASSIVE_LISTEN_MODE; | |
| 253 | + cmd.disc_configs[cmd.num_disc_configs].frequency = 1; | |
| 254 | + cmd.num_disc_configs++; | |
| 255 | + cmd.disc_configs[cmd.num_disc_configs].rf_tech_and_mode = | |
| 256 | + NCI_NFC_F_PASSIVE_LISTEN_MODE; | |
| 257 | + cmd.disc_configs[cmd.num_disc_configs].frequency = 1; | |
| 258 | + cmd.num_disc_configs++; | |
| 259 | + } | |
| 260 | + | |
| 242 | 261 | nci_send_cmd(ndev, NCI_OP_RF_DISCOVER_CMD, |
| 243 | 262 | (1 + (cmd.num_disc_configs * sizeof(struct disc_config))), |
| 244 | 263 | &cmd); |
| @@ -280,7 +299,7 @@ static void nci_rf_deactivate_req(struct nci_dev *ndev, unsigned long opt) · 35 unmodified lines | ||
| 280 | 299 | { |
| 281 | 300 | struct nci_rf_deactivate_cmd cmd; |
| 282 | 301 | |
| 283 | − cmd.type = NCI_DEACTIVATE_TYPE_IDLE_MODE; | |
| 302 | + cmd.type = opt; | |
| 284 | 303 | |
| 285 | 304 | nci_send_cmd(ndev, NCI_OP_RF_DEACTIVATE_CMD, |
| 286 | 305 | sizeof(struct nci_rf_deactivate_cmd), &cmd); |
| @@ -441,6 +460,7 @@ static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev) · 154 unmodified lines | ||
| 441 | 460 | { |
| 442 | 461 | struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); |
| 443 | 462 | struct nci_set_config_param param; |
| 463 | + int rc; | |
| 444 | 464 | |
| 445 | 465 | param.val = nfc_get_local_general_bytes(nfc_dev, ¶m.len); |
| 446 | 466 | if ((param.val == NULL) || (param.len == 0)) |
| @@ -451,14 +471,45 @@ static int nci_set_local_general_bytes(struct nfc_dev *nfc_dev) · 4 unmodified lines | ||
| 451 | 471 | |
| 452 | 472 | param.id = NCI_PN_ATR_REQ_GEN_BYTES; |
| 453 | 473 | |
| 474 | + rc = nci_request(ndev, nci_set_config_req, (unsigned long)¶m, | |
| 475 | + msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT)); | |
| 476 | + if (rc) | |
| 477 | + return rc; | |
| 478 | + | |
| 479 | + param.id = NCI_LN_ATR_RES_GEN_BYTES; | |
| 480 | + | |
| 454 | 481 | return nci_request(ndev, nci_set_config_req, (unsigned long)¶m, |
| 455 | 482 | msecs_to_jiffies(NCI_SET_CONFIG_TIMEOUT)); |
| 456 | 483 | } |
| 457 | 484 | |
| 485 | +static int nci_set_listen_parameters(struct nfc_dev *nfc_dev) | |
| 486 | +{ | |
| 487 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 488 | + int rc; | |
| 489 | + __u8 val; | |
| 490 | + | |
| 491 | + val = NCI_LA_SEL_INFO_NFC_DEP_MASK; | |
| 492 | + | |
| 493 | + rc = nci_set_config(ndev, NCI_LA_SEL_INFO, 1, &val); | |
| 494 | + if (rc) | |
| 495 | + return rc; | |
| 496 | + | |
| 497 | + val = NCI_LF_PROTOCOL_TYPE_NFC_DEP_MASK; | |
| 498 | + | |
| 499 | + rc = nci_set_config(ndev, NCI_LF_PROTOCOL_TYPE, 1, &val); | |
| 500 | + if (rc) | |
| 501 | + return rc; | |
| 502 | + | |
| 503 | + val = NCI_LF_CON_BITR_F_212 | NCI_LF_CON_BITR_F_424; | |
| 504 | + | |
| 505 | + return nci_set_config(ndev, NCI_LF_CON_BITR_F, 1, &val); | |
| 506 | +} | |
| 507 | + | |
| 458 | 508 | static int nci_start_poll(struct nfc_dev *nfc_dev, |
| 459 | 509 | __u32 im_protocols, __u32 tm_protocols) |
| 460 | 510 | { |
| 461 | 511 | struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); |
| 512 | + struct nci_rf_discover_param param; | |
| 462 | 513 | int rc; |
| 463 | 514 | |
| 464 | 515 | if ((atomic_read(&ndev->state) == NCI_DISCOVERY) || |
| @@ -476,13 +527,14 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, · 11 unmodified lines | ||
| 476 | 527 | (atomic_read(&ndev->state) == NCI_POLL_ACTIVE)) { |
| 477 | 528 | pr_debug("target active or w4 select, implicitly deactivate\n"); |
| 478 | 529 | |
| 479 | − rc = nci_request(ndev, nci_rf_deactivate_req, 0, | |
| 530 | + rc = nci_request(ndev, nci_rf_deactivate_req, | |
| 531 | + NCI_DEACTIVATE_TYPE_IDLE_MODE, | |
| 480 | 532 | msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); |
| 481 | 533 | if (rc) |
| 482 | 534 | return -EBUSY; |
| 483 | 535 | } |
| 484 | 536 | |
| 485 | − if (im_protocols & NFC_PROTO_NFC_DEP_MASK) { | |
| 537 | + if ((im_protocols | tm_protocols) & NFC_PROTO_NFC_DEP_MASK) { | |
| 486 | 538 | rc = nci_set_local_general_bytes(nfc_dev); |
| 487 | 539 | if (rc) { |
| 488 | 540 | pr_err("failed to set local general bytes\n"); |
| @@ -490,7 +542,15 @@ static int nci_start_poll(struct nfc_dev *nfc_dev, · 1 unmodified line | ||
| 490 | 542 | } |
| 491 | 543 | } |
| 492 | 544 | |
| 493 | − rc = nci_request(ndev, nci_rf_discover_req, im_protocols, | |
| 545 | + if (tm_protocols & NFC_PROTO_NFC_DEP_MASK) { | |
| 546 | + rc = nci_set_listen_parameters(nfc_dev); | |
| 547 | + if (rc) | |
| 548 | + pr_err("failed to set listen parameters\n"); | |
| 549 | + } | |
| 550 | + | |
| 551 | + param.im_protocols = im_protocols; | |
| 552 | + param.tm_protocols = tm_protocols; | |
| 553 | + rc = nci_request(ndev, nci_rf_discover_req, (unsigned long)¶m, | |
| 494 | 554 | msecs_to_jiffies(NCI_RF_DISC_TIMEOUT)); |
| 495 | 555 | |
| 496 | 556 | if (!rc) |
| @@ -509,7 +569,7 @@ static void nci_stop_poll(struct nfc_dev *nfc_dev) · 12 unmodified lines | ||
| 509 | 569 | return; |
| 510 | 570 | } |
| 511 | 571 | |
| 512 | − nci_request(ndev, nci_rf_deactivate_req, 0, | |
| 572 | + nci_request(ndev, nci_rf_deactivate_req, NCI_DEACTIVATE_TYPE_IDLE_MODE, | |
| 513 | 573 | msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); |
| 514 | 574 | } |
| 515 | 575 | |
| @@ -594,7 +654,8 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev, · 78 unmodified lines | ||
| 594 | 654 | ndev->target_active_prot = 0; |
| 595 | 655 | |
| 596 | 656 | if (atomic_read(&ndev->state) == NCI_POLL_ACTIVE) { |
| 597 | − nci_request(ndev, nci_rf_deactivate_req, 0, | |
| 657 | + nci_request(ndev, nci_rf_deactivate_req, | |
| 658 | + NCI_DEACTIVATE_TYPE_SLEEP_MODE, | |
| 598 | 659 | msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); |
| 599 | 660 | } |
| 600 | 661 | } |
| @@ -622,9 +683,24 @@ static int nci_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, · 21 unmodified lines | ||
| 622 | 683 | |
| 623 | 684 | static int nci_dep_link_down(struct nfc_dev *nfc_dev) |
| 624 | 685 | { |
| 686 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 687 | + int rc; | |
| 688 | + | |
| 625 | 689 | pr_debug("entry\n"); |
| 626 | 690 | |
| 627 | − nci_deactivate_target(nfc_dev, NULL); | |
| 691 | + if (nfc_dev->rf_mode == NFC_RF_INITIATOR) { | |
| 692 | + nci_deactivate_target(nfc_dev, NULL); | |
| 693 | + } else { | |
| 694 | + if (atomic_read(&ndev->state) == NCI_LISTEN_ACTIVE || | |
| 695 | + atomic_read(&ndev->state) == NCI_DISCOVERY) { | |
| 696 | + nci_request(ndev, nci_rf_deactivate_req, 0, | |
| 697 | + msecs_to_jiffies(NCI_RF_DEACTIVATE_TIMEOUT)); | |
| 698 | + } | |
| 699 | + | |
| 700 | + rc = nfc_tm_deactivated(nfc_dev); | |
| 701 | + if (rc) | |
| 702 | + pr_err("error when signaling tm deactivation\n"); | |
| 703 | + } | |
| 628 | 704 | |
| 629 | 705 | return 0; |
| 630 | 706 | } |
| @@ -658,18 +734,58 @@ static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target, · 27 unmodified lines | ||
| 658 | 734 | return rc; |
| 659 | 735 | } |
| 660 | 736 | |
| 737 | +static int nci_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb) | |
| 738 | +{ | |
| 739 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 740 | + int rc; | |
| 741 | + | |
| 742 | + rc = nci_send_data(ndev, NCI_STATIC_RF_CONN_ID, skb); | |
| 743 | + if (rc) | |
| 744 | + pr_err("unable to send data\n"); | |
| 745 | + | |
| 746 | + return rc; | |
| 747 | +} | |
| 748 | + | |
| 661 | 749 | static int nci_enable_se(struct nfc_dev *nfc_dev, u32 se_idx) |
| 662 | 750 | { |
| 751 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 752 | + | |
| 753 | + if (ndev->ops->enable_se) | |
| 754 | + return ndev->ops->enable_se(ndev, se_idx); | |
| 755 | + | |
| 663 | 756 | return 0; |
| 664 | 757 | } |
| 665 | 758 | |
| 666 | 759 | static int nci_disable_se(struct nfc_dev *nfc_dev, u32 se_idx) |
| 667 | 760 | { |
| 761 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 762 | + | |
| 763 | + if (ndev->ops->disable_se) | |
| 764 | + return ndev->ops->disable_se(ndev, se_idx); | |
| 765 | + | |
| 668 | 766 | return 0; |
| 669 | 767 | } |
| 670 | 768 | |
| 671 | 769 | static int nci_discover_se(struct nfc_dev *nfc_dev) |
| 672 | 770 | { |
| 771 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 772 | + | |
| 773 | + if (ndev->ops->discover_se) | |
| 774 | + return ndev->ops->discover_se(ndev); | |
| 775 | + | |
| 776 | + return 0; | |
| 777 | +} | |
| 778 | + | |
| 779 | +static int nci_se_io(struct nfc_dev *nfc_dev, u32 se_idx, | |
| 780 | + u8 *apdu, size_t apdu_length, | |
| 781 | + se_io_cb_t cb, void *cb_context) | |
| 782 | +{ | |
| 783 | + struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); | |
| 784 | + | |
| 785 | + if (ndev->ops->se_io) | |
| 786 | + return ndev->ops->se_io(ndev, se_idx, apdu, | |
| 787 | + apdu_length, cb, cb_context); | |
| 788 | + | |
| 673 | 789 | return 0; |
| 674 | 790 | } |
| 675 | 791 | |
| @@ -683,9 +799,11 @@ static struct nfc_ops nci_nfc_ops = { · 7 unmodified lines | ||
| 683 | 799 | .activate_target = nci_activate_target, |
| 684 | 800 | .deactivate_target = nci_deactivate_target, |
| 685 | 801 | .im_transceive = nci_transceive, |
| 802 | + .tm_send = nci_tm_send, | |
| 686 | 803 | .enable_se = nci_enable_se, |
| 687 | 804 | .disable_se = nci_disable_se, |
| 688 | 805 | .discover_se = nci_discover_se, |
| 806 | + .se_io = nci_se_io, | |
| 689 | 807 | }; |
| 690 | 808 | |
| 691 | 809 | /* ---- Interface to NCI drivers ---- */ |
| @@ -3,6 +3,7 @@ · 2 unmodified lines | ||
| 3 | 3 | * NFC Controller (NFCC) and a Device Host (DH). |
| 4 | 4 | * |
| 5 | 5 | * Copyright (C) 2011 Texas Instruments, Inc. |
| 6 | + * Copyright (C) 2014 Marvell International Ltd. | |
| 6 | 7 | * |
| 7 | 8 | * Written by Ilan Elias <ilane@ti.com> |
| 8 | 9 | * |
| @@ -184,11 +185,16 @@ exit: · 175 unmodified lines | ||
| 184 | 185 | |
| 185 | 186 | static void nci_add_rx_data_frag(struct nci_dev *ndev, |
| 186 | 187 | struct sk_buff *skb, |
| 187 | − __u8 pbf) | |
| 188 | + __u8 pbf, __u8 status) | |
| 188 | 189 | { |
| 189 | 190 | int reassembly_len; |
| 190 | 191 | int err = 0; |
| 191 | 192 | |
| 193 | + if (status) { | |
| 194 | + err = status; | |
| 195 | + goto exit; | |
| 196 | + } | |
| 197 | + | |
| 192 | 198 | if (ndev->rx_data_reassembly) { |
| 193 | 199 | reassembly_len = ndev->rx_data_reassembly->len; |
| 194 | 200 | |
| @@ -223,13 +229,24 @@ static void nci_add_rx_data_frag(struct nci_dev *ndev, · 28 unmodified lines | ||
| 223 | 229 | } |
| 224 | 230 | |
| 225 | 231 | exit: |
| 226 | − nci_data_exchange_complete(ndev, skb, err); | |
| 232 | + if (ndev->nfc_dev->rf_mode == NFC_RF_INITIATOR) { | |
| 233 | + nci_data_exchange_complete(ndev, skb, err); | |
| 234 | + } else if (ndev->nfc_dev->rf_mode == NFC_RF_TARGET) { | |
| 235 | + /* Data received in Target mode, forward to nfc core */ | |
| 236 | + err = nfc_tm_data_received(ndev->nfc_dev, skb); | |
| 237 | + if (err) | |
| 238 | + pr_err("unable to handle received data\n"); | |
| 239 | + } else { | |
| 240 | + pr_err("rf mode unknown\n"); | |
| 241 | + kfree_skb(skb); | |
| 242 | + } | |
| 227 | 243 | } |
| 228 | 244 | |
| 229 | 245 | /* Rx Data packet */ |
| 230 | 246 | void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb) |
| 231 | 247 | { |
| 232 | 248 | __u8 pbf = nci_pbf(skb->data); |
| 249 | + __u8 status = 0; | |
| 233 | 250 | |
| 234 | 251 | pr_debug("len %d\n", skb->len); |
| 235 | 252 | |
| @@ -247,8 +264,9 @@ void nci_rx_data_packet(struct nci_dev *ndev, struct sk_buff *skb) · 11 unmodified lines | ||
| 247 | 264 | ndev->target_active_prot == NFC_PROTO_ISO15693) { |
| 248 | 265 | /* frame I/F => remove the status byte */ |
| 249 | 266 | pr_debug("frame I/F => remove the status byte\n"); |
| 267 | + status = skb->data[skb->len - 1]; | |
| 250 | 268 | skb_trim(skb, (skb->len - 1)); |
| 251 | 269 | } |
| 252 | 270 | |
| 253 | − nci_add_rx_data_frag(ndev, skb, pbf); | |
| 271 | + nci_add_rx_data_frag(ndev, skb, pbf, nci_to_errno(status)); | |
| 254 | 272 | } |
| @@ -103,7 +103,7 @@ static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev, · 102 unmodified lines | ||
| 103 | 103 | struct rf_tech_specific_params_nfca_poll *nfca_poll, |
| 104 | 104 | __u8 *data) |
| 105 | 105 | { |
| 106 | − nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data)); | |
| 106 | + nfca_poll->sens_res = __le16_to_cpu(*((__le16 *)data)); | |
| 107 | 107 | data += 2; |
| 108 | 108 | |
| 109 | 109 | nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE); |
| @@ -167,7 +167,19 @@ static __u8 *nci_extract_rf_params_nfcv_passive_poll(struct nci_dev *ndev, · 57 unmodified lines | ||
| 167 | 167 | return data; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | −__u32 nci_get_prop_rf_protocol(struct nci_dev *ndev, __u8 rf_protocol) | |
| 170 | +static __u8 *nci_extract_rf_params_nfcf_passive_listen(struct nci_dev *ndev, | |
| 171 | + struct rf_tech_specific_params_nfcf_listen *nfcf_listen, | |
| 172 | + __u8 *data) | |
| 173 | +{ | |
| 174 | + nfcf_listen->local_nfcid2_len = min_t(__u8, *data++, | |
| 175 | + NFC_NFCID2_MAXSIZE); | |
| 176 | + memcpy(nfcf_listen->local_nfcid2, data, nfcf_listen->local_nfcid2_len); | |
| 177 | + data += nfcf_listen->local_nfcid2_len; | |
| 178 | + | |
| 179 | + return data; | |
| 180 | +} | |
| 181 | + | |
| 182 | +static __u32 nci_get_prop_rf_protocol(struct nci_dev *ndev, __u8 rf_protocol) | |
| 171 | 183 | { |
| 172 | 184 | if (ndev->ops->get_rfprotocol) |
| 173 | 185 | return ndev->ops->get_rfprotocol(ndev, rf_protocol); |
| @@ -401,17 +413,29 @@ static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev, · 227 unmodified lines | ||
| 401 | 413 | struct nci_rf_intf_activated_ntf *ntf, __u8 *data) |
| 402 | 414 | { |
| 403 | 415 | struct activation_params_poll_nfc_dep *poll; |
| 416 | + struct activation_params_listen_nfc_dep *listen; | |
| 404 | 417 | |
| 405 | 418 | switch (ntf->activation_rf_tech_and_mode) { |
| 406 | 419 | case NCI_NFC_A_PASSIVE_POLL_MODE: |
| 407 | 420 | case NCI_NFC_F_PASSIVE_POLL_MODE: |
| 408 | 421 | poll = &ntf->activation_params.poll_nfc_dep; |
| 409 | − poll->atr_res_len = min_t(__u8, *data++, 63); | |
| 422 | + poll->atr_res_len = min_t(__u8, *data++, | |
| 423 | + NFC_ATR_RES_MAXSIZE - 2); | |
| 410 | 424 | pr_debug("atr_res_len %d\n", poll->atr_res_len); |
| 411 | 425 | if (poll->atr_res_len > 0) |
| 412 | 426 | memcpy(poll->atr_res, data, poll->atr_res_len); |
| 413 | 427 | break; |
| 414 | 428 | |
| 429 | + case NCI_NFC_A_PASSIVE_LISTEN_MODE: | |
| 430 | + case NCI_NFC_F_PASSIVE_LISTEN_MODE: | |
| 431 | + listen = &ntf->activation_params.listen_nfc_dep; | |
| 432 | + listen->atr_req_len = min_t(__u8, *data++, | |
| 433 | + NFC_ATR_REQ_MAXSIZE - 2); | |
| 434 | + pr_debug("atr_req_len %d\n", listen->atr_req_len); | |
| 435 | + if (listen->atr_req_len > 0) | |
| 436 | + memcpy(listen->atr_req, data, listen->atr_req_len); | |
| 437 | + break; | |
| 438 | + | |
| 415 | 439 | default: |
| 416 | 440 | pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", |
| 417 | 441 | ntf->activation_rf_tech_and_mode); |
| @@ -444,6 +468,48 @@ static void nci_target_auto_activated(struct nci_dev *ndev, · 26 unmodified lines | ||
| 444 | 468 | nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets); |
| 445 | 469 | } |
| 446 | 470 | |
| 471 | +static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev, | |
| 472 | + struct nci_rf_intf_activated_ntf *ntf) | |
| 473 | +{ | |
| 474 | + ndev->remote_gb_len = 0; | |
| 475 | + | |
| 476 | + if (ntf->activation_params_len <= 0) | |
| 477 | + return NCI_STATUS_OK; | |
| 478 | + | |
| 479 | + switch (ntf->activation_rf_tech_and_mode) { | |
| 480 | + case NCI_NFC_A_PASSIVE_POLL_MODE: | |
| 481 | + case NCI_NFC_F_PASSIVE_POLL_MODE: | |
| 482 | + ndev->remote_gb_len = min_t(__u8, | |
| 483 | + (ntf->activation_params.poll_nfc_dep.atr_res_len | |
| 484 | + - NFC_ATR_RES_GT_OFFSET), | |
| 485 | + NFC_ATR_RES_GB_MAXSIZE); | |
| 486 | + memcpy(ndev->remote_gb, | |
| 487 | + (ntf->activation_params.poll_nfc_dep.atr_res | |
| 488 | + + NFC_ATR_RES_GT_OFFSET), | |
| 489 | + ndev->remote_gb_len); | |
| 490 | + break; | |
| 491 | + | |
| 492 | + case NCI_NFC_A_PASSIVE_LISTEN_MODE: | |
| 493 | + case NCI_NFC_F_PASSIVE_LISTEN_MODE: | |
| 494 | + ndev->remote_gb_len = min_t(__u8, | |
| 495 | + (ntf->activation_params.listen_nfc_dep.atr_req_len | |
| 496 | + - NFC_ATR_REQ_GT_OFFSET), | |
| 497 | + NFC_ATR_REQ_GB_MAXSIZE); | |
| 498 | + memcpy(ndev->remote_gb, | |
| 499 | + (ntf->activation_params.listen_nfc_dep.atr_req | |
| 500 | + + NFC_ATR_REQ_GT_OFFSET), | |
| 501 | + ndev->remote_gb_len); | |
| 502 | + break; | |
| 503 | + | |
| 504 | + default: | |
| 505 | + pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", | |
| 506 | + ntf->activation_rf_tech_and_mode); | |
| 507 | + return NCI_STATUS_RF_PROTOCOL_ERROR; | |
| 508 | + } | |
| 509 | + | |
| 510 | + return NCI_STATUS_OK; | |
| 511 | +} | |
| 512 | + | |
| 447 | 513 | static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev, |
| 448 | 514 | struct sk_buff *skb) |
| 449 | 515 | { |
| @@ -493,6 +559,16 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev, · 43 unmodified lines | ||
| 493 | 559 | &(ntf.rf_tech_specific_params.nfcv_poll), data); |
| 494 | 560 | break; |
| 495 | 561 | |
| 562 | + case NCI_NFC_A_PASSIVE_LISTEN_MODE: | |
| 563 | + /* no RF technology specific parameters */ | |
| 564 | + break; | |
| 565 | + | |
| 566 | + case NCI_NFC_F_PASSIVE_LISTEN_MODE: | |
| 567 | + data = nci_extract_rf_params_nfcf_passive_listen(ndev, | |
| 568 | + &(ntf.rf_tech_specific_params.nfcf_listen), | |
| 569 | + data); | |
| 570 | + break; | |
| 571 | + | |
| 496 | 572 | default: |
| 497 | 573 | pr_err("unsupported activation_rf_tech_and_mode 0x%x\n", |
| 498 | 574 | ntf.activation_rf_tech_and_mode); |
| @@ -546,32 +622,39 @@ exit: · 47 unmodified lines | ||
| 546 | 622 | |
| 547 | 623 | /* store general bytes to be reported later in dep_link_up */ |
| 548 | 624 | if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) { |
| 549 | − ndev->remote_gb_len = 0; | |
| 550 | − | |
| 551 | − if (ntf.activation_params_len > 0) { | |
| 552 | − /* ATR_RES general bytes at offset 15 */ | |
| 553 | − ndev->remote_gb_len = min_t(__u8, | |
| 554 | − (ntf.activation_params | |
| 555 | − .poll_nfc_dep.atr_res_len | |
| 556 | − - NFC_ATR_RES_GT_OFFSET), | |
| 557 | − NFC_MAX_GT_LEN); | |
| 558 | − memcpy(ndev->remote_gb, | |
| 559 | − (ntf.activation_params.poll_nfc_dep | |
| 560 | − .atr_res + NFC_ATR_RES_GT_OFFSET), | |
| 561 | − ndev->remote_gb_len); | |
| 562 | − } | |
| 625 | + err = nci_store_general_bytes_nfc_dep(ndev, &ntf); | |
| 626 | + if (err != NCI_STATUS_OK) | |
| 627 | + pr_err("unable to store general bytes\n"); | |
| 563 | 628 | } |
| 564 | 629 | } |
| 565 | 630 | |
| 566 | − if (atomic_read(&ndev->state) == NCI_DISCOVERY) { | |
| 567 | − /* A single target was found and activated automatically */ | |
| 568 | − atomic_set(&ndev->state, NCI_POLL_ACTIVE); | |
| 569 | − if (err == NCI_STATUS_OK) | |
| 570 | − nci_target_auto_activated(ndev, &ntf); | |
| 571 | − } else { /* ndev->state == NCI_W4_HOST_SELECT */ | |
| 572 | − /* A selected target was activated, so complete the request */ | |
| 573 | − atomic_set(&ndev->state, NCI_POLL_ACTIVE); | |
| 574 | − nci_req_complete(ndev, err); | |
| 631 | + if (!(ntf.activation_rf_tech_and_mode & NCI_RF_TECH_MODE_LISTEN_MASK)) { | |
| 632 | + /* Poll mode */ | |
| 633 | + if (atomic_read(&ndev->state) == NCI_DISCOVERY) { | |
| 634 | + /* A single target was found and activated | |
| 635 | + * automatically */ | |
| 636 | + atomic_set(&ndev->state, NCI_POLL_ACTIVE); | |
| 637 | + if (err == NCI_STATUS_OK) | |
| 638 | + nci_target_auto_activated(ndev, &ntf); | |
| 639 | + } else { /* ndev->state == NCI_W4_HOST_SELECT */ | |
| 640 | + /* A selected target was activated, so complete the | |
| 641 | + * request */ | |
| 642 | + atomic_set(&ndev->state, NCI_POLL_ACTIVE); | |
| 643 | + nci_req_complete(ndev, err); | |
| 644 | + } | |
| 645 | + } else { | |
| 646 | + /* Listen mode */ | |
| 647 | + atomic_set(&ndev->state, NCI_LISTEN_ACTIVE); | |
| 648 | + if (err == NCI_STATUS_OK && | |
| 649 | + ntf.rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) { | |
| 650 | + err = nfc_tm_activated(ndev->nfc_dev, | |
| 651 | + NFC_PROTO_NFC_DEP_MASK, | |
| 652 | + NFC_COMM_PASSIVE, | |
| 653 | + ndev->remote_gb, | |
| 654 | + ndev->remote_gb_len); | |
| 655 | + if (err != NCI_STATUS_OK) | |
| 656 | + pr_err("error when signaling tm activation\n"); | |
| 657 | + } | |
| 575 | 658 | } |
| 576 | 659 | } |
| 577 | 660 | |
| @@ -595,8 +678,21 @@ static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev, · 17 unmodified lines | ||
| 595 | 678 | if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags)) |
| 596 | 679 | nci_data_exchange_complete(ndev, NULL, -EIO); |
| 597 | 680 | |
| 598 | − nci_clear_target_list(ndev); | |
| 599 | − atomic_set(&ndev->state, NCI_IDLE); | |
| 681 | + switch (ntf->type) { | |
| 682 | + case NCI_DEACTIVATE_TYPE_IDLE_MODE: | |
| 683 | + nci_clear_target_list(ndev); | |
| 684 | + atomic_set(&ndev->state, NCI_IDLE); | |
| 685 | + break; | |
| 686 | + case NCI_DEACTIVATE_TYPE_SLEEP_MODE: | |
| 687 | + case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE: | |
| 688 | + atomic_set(&ndev->state, NCI_W4_HOST_SELECT); | |
| 689 | + break; | |
| 690 | + case NCI_DEACTIVATE_TYPE_DISCOVERY: | |
| 691 | + nci_clear_target_list(ndev); | |
| 692 | + atomic_set(&ndev->state, NCI_DISCOVERY); | |
| 693 | + break; | |
| 694 | + } | |
| 695 | + | |
| 600 | 696 | nci_req_complete(ndev, NCI_STATUS_OK); |
| 601 | 697 | } |
| 602 | 698 | |
| @@ -810,6 +810,31 @@ out: · 809 unmodified lines | ||
| 810 | 810 | return rc; |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | +static int nfc_genl_activate_target(struct sk_buff *skb, struct genl_info *info) | |
| 814 | +{ | |
| 815 | + struct nfc_dev *dev; | |
| 816 | + u32 device_idx, target_idx, protocol; | |
| 817 | + int rc; | |
| 818 | + | |
| 819 | + if (!info->attrs[NFC_ATTR_DEVICE_INDEX]) | |
| 820 | + return -EINVAL; | |
| 821 | + | |
| 822 | + device_idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]); | |
| 823 | + | |
| 824 | + dev = nfc_get_device(device_idx); | |
| 825 | + if (!dev) | |
| 826 | + return -ENODEV; | |
| 827 | + | |
| 828 | + target_idx = nla_get_u32(info->attrs[NFC_ATTR_TARGET_INDEX]); | |
| 829 | + protocol = nla_get_u32(info->attrs[NFC_ATTR_PROTOCOLS]); | |
| 830 | + | |
| 831 | + nfc_deactivate_target(dev, target_idx); | |
| 832 | + rc = nfc_activate_target(dev, target_idx, protocol); | |
| 833 | + | |
| 834 | + nfc_put_device(dev); | |
| 835 | + return 0; | |
| 836 | +} | |
| 837 | + | |
| 813 | 838 | static int nfc_genl_dep_link_up(struct sk_buff *skb, struct genl_info *info) |
| 814 | 839 | { |
| 815 | 840 | struct nfc_dev *dev; |
| @@ -1285,6 +1310,51 @@ static int nfc_genl_dump_ses_done(struct netlink_callback *cb) · 469 unmodified lines | ||
| 1285 | 1310 | return 0; |
| 1286 | 1311 | } |
| 1287 | 1312 | |
| 1313 | +static int nfc_se_io(struct nfc_dev *dev, u32 se_idx, | |
| 1314 | + u8 *apdu, size_t apdu_length, | |
| 1315 | + se_io_cb_t cb, void *cb_context) | |
| 1316 | +{ | |
| 1317 | + struct nfc_se *se; | |
| 1318 | + int rc; | |
| 1319 | + | |
| 1320 | + pr_debug("%s se index %d\n", dev_name(&dev->dev), se_idx); | |
| 1321 | + | |
| 1322 | + device_lock(&dev->dev); | |
| 1323 | + | |
| 1324 | + if (!device_is_registered(&dev->dev)) { | |
| 1325 | + rc = -ENODEV; | |
| 1326 | + goto error; | |
| 1327 | + } | |
| 1328 | + | |
| 1329 | + if (!dev->dev_up) { | |
| 1330 | + rc = -ENODEV; | |
| 1331 | + goto error; | |
| 1332 | + } | |
| 1333 | + | |
| 1334 | + if (!dev->ops->se_io) { | |
| 1335 | + rc = -EOPNOTSUPP; | |
| 1336 | + goto error; | |
| 1337 | + } | |
| 1338 | + | |
| 1339 | + se = nfc_find_se(dev, se_idx); | |
| 1340 | + if (!se) { | |
| 1341 | + rc = -EINVAL; | |
| 1342 | + goto error; | |
| 1343 | + } | |
| 1344 | + | |
| 1345 | + if (se->state != NFC_SE_ENABLED) { | |
| 1346 | + rc = -ENODEV; | |
| 1347 | + goto error; | |
| 1348 | + } | |
| 1349 | + | |
| 1350 | + rc = dev->ops->se_io(dev, se_idx, apdu, | |
| 1351 | + apdu_length, cb, cb_context); | |
| 1352 | + | |
| 1353 | +error: | |
| 1354 | + device_unlock(&dev->dev); | |
| 1355 | + return rc; | |
| 1356 | +} | |
| 1357 | + | |
| 1288 | 1358 | struct se_io_ctx { |
| 1289 | 1359 | u32 dev_idx; |
| 1290 | 1360 | u32 se_idx; |
| @@ -1367,7 +1437,7 @@ static int nfc_genl_se_io(struct sk_buff *skb, struct genl_info *info) · 76 unmodified lines | ||
| 1367 | 1437 | ctx->dev_idx = dev_idx; |
| 1368 | 1438 | ctx->se_idx = se_idx; |
| 1369 | 1439 | |
| 1370 | − return dev->ops->se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx); | |
| 1440 | + return nfc_se_io(dev, se_idx, apdu, apdu_len, se_io_cb, ctx); | |
| 1371 | 1441 | } |
| 1372 | 1442 | |
| 1373 | 1443 | static const struct genl_ops nfc_genl_ops[] = { |
| @@ -1455,6 +1525,11 @@ static const struct genl_ops nfc_genl_ops[] = { · 81 unmodified lines | ||
| 1455 | 1525 | .doit = nfc_genl_se_io, |
| 1456 | 1526 | .policy = nfc_genl_policy, |
| 1457 | 1527 | }, |
| 1528 | + { | |
| 1529 | + .cmd = NFC_CMD_ACTIVATE_TARGET, | |
| 1530 | + .doit = nfc_genl_activate_target, | |
| 1531 | + .policy = nfc_genl_policy, | |
| 1532 | + }, | |
| 1458 | 1533 | }; |
| 1459 | 1534 | |
| 1460 | 1535 | |