diff options
author | Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> | 2012-12-10 08:42:45 -0500 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-01-09 18:51:35 -0500 |
commit | 13003649b1ebb4ea51341a9405a2ec5b10cf4f7e (patch) | |
tree | eb4f8062a55186e3ad6188d121792f48a725f7d2 /drivers/nfc | |
parent | e487882345a80a17b534182ab1f259f2321e4fed (diff) |
NFC: pn533: Del frame logic from InJumForDep cmd
Remove frame logic from InJmumpForDEP command using
the new iface for async send.
Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/nfc')
-rw-r--r-- | drivers/nfc/pn533.c | 117 |
1 files changed, 55 insertions, 62 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index 9912824030f6..aa7803f16773 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -298,14 +298,6 @@ struct pn533_cmd_activate_response { | |||
298 | u8 gt[]; | 298 | u8 gt[]; |
299 | } __packed; | 299 | } __packed; |
300 | 300 | ||
301 | /* PN533_CMD_IN_JUMP_FOR_DEP */ | ||
302 | struct pn533_cmd_jump_dep { | ||
303 | u8 active; | ||
304 | u8 baud; | ||
305 | u8 next; | ||
306 | u8 data[]; | ||
307 | } __packed; | ||
308 | |||
309 | struct pn533_cmd_jump_dep_response { | 301 | struct pn533_cmd_jump_dep_response { |
310 | u8 status; | 302 | u8 status; |
311 | u8 tg; | 303 | u8 tg; |
@@ -1861,53 +1853,46 @@ static void pn533_deactivate_target(struct nfc_dev *nfc_dev, | |||
1861 | 1853 | ||
1862 | 1854 | ||
1863 | static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg, | 1855 | static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg, |
1864 | u8 *params, int params_len) | 1856 | struct sk_buff *resp) |
1865 | { | 1857 | { |
1866 | struct pn533_cmd_jump_dep_response *resp; | 1858 | struct pn533_cmd_jump_dep_response *rsp; |
1867 | struct nfc_target nfc_target; | ||
1868 | u8 target_gt_len; | 1859 | u8 target_gt_len; |
1869 | int rc; | 1860 | int rc; |
1870 | struct pn533_cmd_jump_dep *cmd = (struct pn533_cmd_jump_dep *)arg; | 1861 | u8 active = *(u8 *)arg; |
1871 | u8 active = cmd->active; | ||
1872 | 1862 | ||
1873 | kfree(arg); | 1863 | kfree(arg); |
1874 | 1864 | ||
1875 | if (params_len == -ENOENT) { | 1865 | if (IS_ERR(resp)) |
1876 | nfc_dev_dbg(&dev->interface->dev, ""); | 1866 | return PTR_ERR(resp); |
1877 | return 0; | ||
1878 | } | ||
1879 | |||
1880 | if (params_len < 0) { | ||
1881 | nfc_dev_err(&dev->interface->dev, | ||
1882 | "Error %d when bringing DEP link up", | ||
1883 | params_len); | ||
1884 | return 0; | ||
1885 | } | ||
1886 | 1867 | ||
1887 | if (dev->tgt_available_prots && | 1868 | if (dev->tgt_available_prots && |
1888 | !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) { | 1869 | !(dev->tgt_available_prots & (1 << NFC_PROTO_NFC_DEP))) { |
1889 | nfc_dev_err(&dev->interface->dev, | 1870 | nfc_dev_err(&dev->interface->dev, |
1890 | "The target does not support DEP"); | 1871 | "The target does not support DEP"); |
1891 | return -EINVAL; | 1872 | rc = -EINVAL; |
1873 | goto error; | ||
1892 | } | 1874 | } |
1893 | 1875 | ||
1894 | resp = (struct pn533_cmd_jump_dep_response *) params; | 1876 | rsp = (struct pn533_cmd_jump_dep_response *)resp->data; |
1895 | rc = resp->status & PN533_CMD_RET_MASK; | 1877 | |
1878 | rc = rsp->status & PN533_CMD_RET_MASK; | ||
1896 | if (rc != PN533_CMD_RET_SUCCESS) { | 1879 | if (rc != PN533_CMD_RET_SUCCESS) { |
1897 | nfc_dev_err(&dev->interface->dev, | 1880 | nfc_dev_err(&dev->interface->dev, |
1898 | "Bringing DEP link up failed %d", rc); | 1881 | "Bringing DEP link up failed %d", rc); |
1899 | return 0; | 1882 | goto error; |
1900 | } | 1883 | } |
1901 | 1884 | ||
1902 | if (!dev->tgt_available_prots) { | 1885 | if (!dev->tgt_available_prots) { |
1886 | struct nfc_target nfc_target; | ||
1887 | |||
1903 | nfc_dev_dbg(&dev->interface->dev, "Creating new target"); | 1888 | nfc_dev_dbg(&dev->interface->dev, "Creating new target"); |
1904 | 1889 | ||
1905 | nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK; | 1890 | nfc_target.supported_protocols = NFC_PROTO_NFC_DEP_MASK; |
1906 | nfc_target.nfcid1_len = 10; | 1891 | nfc_target.nfcid1_len = 10; |
1907 | memcpy(nfc_target.nfcid1, resp->nfcid3t, nfc_target.nfcid1_len); | 1892 | memcpy(nfc_target.nfcid1, rsp->nfcid3t, nfc_target.nfcid1_len); |
1908 | rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1); | 1893 | rc = nfc_targets_found(dev->nfc_dev, &nfc_target, 1); |
1909 | if (rc) | 1894 | if (rc) |
1910 | return 0; | 1895 | goto error; |
1911 | 1896 | ||
1912 | dev->tgt_available_prots = 0; | 1897 | dev->tgt_available_prots = 0; |
1913 | } | 1898 | } |
@@ -1915,15 +1900,17 @@ static int pn533_in_dep_link_up_complete(struct pn533 *dev, void *arg, | |||
1915 | dev->tgt_active_prot = NFC_PROTO_NFC_DEP; | 1900 | dev->tgt_active_prot = NFC_PROTO_NFC_DEP; |
1916 | 1901 | ||
1917 | /* ATR_RES general bytes are located at offset 17 */ | 1902 | /* ATR_RES general bytes are located at offset 17 */ |
1918 | target_gt_len = PN533_FRAME_CMD_PARAMS_LEN(dev->in_frame) - 17; | 1903 | target_gt_len = resp->len - 17; |
1919 | rc = nfc_set_remote_general_bytes(dev->nfc_dev, | 1904 | rc = nfc_set_remote_general_bytes(dev->nfc_dev, |
1920 | resp->gt, target_gt_len); | 1905 | rsp->gt, target_gt_len); |
1921 | if (rc == 0) | 1906 | if (rc == 0) |
1922 | rc = nfc_dep_link_is_up(dev->nfc_dev, | 1907 | rc = nfc_dep_link_is_up(dev->nfc_dev, |
1923 | dev->nfc_dev->targets[0].idx, | 1908 | dev->nfc_dev->targets[0].idx, |
1924 | !active, NFC_RF_INITIATOR); | 1909 | !active, NFC_RF_INITIATOR); |
1925 | 1910 | ||
1926 | return 0; | 1911 | error: |
1912 | dev_kfree_skb(resp); | ||
1913 | return rc; | ||
1927 | } | 1914 | } |
1928 | 1915 | ||
1929 | static int pn533_mod_to_baud(struct pn533 *dev) | 1916 | static int pn533_mod_to_baud(struct pn533 *dev) |
@@ -1945,10 +1932,11 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, | |||
1945 | u8 comm_mode, u8* gb, size_t gb_len) | 1932 | u8 comm_mode, u8* gb, size_t gb_len) |
1946 | { | 1933 | { |
1947 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); | 1934 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); |
1948 | struct pn533_cmd_jump_dep *cmd; | 1935 | struct sk_buff *skb; |
1949 | u8 cmd_len, *data_ptr; | 1936 | int rc, baud, skb_len; |
1937 | u8 *next, *arg; | ||
1938 | |||
1950 | u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3}; | 1939 | u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3}; |
1951 | int rc, baud; | ||
1952 | 1940 | ||
1953 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | 1941 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); |
1954 | 1942 | ||
@@ -1971,43 +1959,48 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, | |||
1971 | return baud; | 1959 | return baud; |
1972 | } | 1960 | } |
1973 | 1961 | ||
1974 | cmd_len = sizeof(struct pn533_cmd_jump_dep) + gb_len; | 1962 | skb_len = 3 + gb_len; /* ActPass + BR + Next */ |
1975 | if (comm_mode == NFC_COMM_PASSIVE) | 1963 | if (comm_mode == NFC_COMM_PASSIVE) |
1976 | cmd_len += PASSIVE_DATA_LEN; | 1964 | skb_len += PASSIVE_DATA_LEN; |
1977 | 1965 | ||
1978 | cmd = kzalloc(cmd_len, GFP_KERNEL); | 1966 | skb = pn533_alloc_skb(skb_len); |
1979 | if (cmd == NULL) | 1967 | if (!skb) |
1980 | return -ENOMEM; | 1968 | return -ENOMEM; |
1981 | 1969 | ||
1982 | pn533_tx_frame_init(dev->out_frame, PN533_CMD_IN_JUMP_FOR_DEP); | 1970 | *skb_put(skb, 1) = !comm_mode; /* ActPass */ |
1971 | *skb_put(skb, 1) = baud; /* Baud rate */ | ||
1972 | |||
1973 | next = skb_put(skb, 1); /* Next */ | ||
1974 | *next = 0; | ||
1983 | 1975 | ||
1984 | cmd->active = !comm_mode; | 1976 | if (comm_mode == NFC_COMM_PASSIVE && baud > 0) { |
1985 | cmd->next = 0; | 1977 | memcpy(skb_put(skb, PASSIVE_DATA_LEN), passive_data, |
1986 | cmd->baud = baud; | 1978 | PASSIVE_DATA_LEN); |
1987 | data_ptr = cmd->data; | 1979 | *next |= 1; |
1988 | if (comm_mode == NFC_COMM_PASSIVE && cmd->baud > 0) { | ||
1989 | memcpy(data_ptr, passive_data, PASSIVE_DATA_LEN); | ||
1990 | cmd->next |= 1; | ||
1991 | data_ptr += PASSIVE_DATA_LEN; | ||
1992 | } | 1980 | } |
1993 | 1981 | ||
1994 | if (gb != NULL && gb_len > 0) { | 1982 | if (gb != NULL && gb_len > 0) { |
1995 | cmd->next |= 4; /* We have some Gi */ | 1983 | memcpy(skb_put(skb, gb_len), gb, gb_len); |
1996 | memcpy(data_ptr, gb, gb_len); | 1984 | *next |= 4; /* We have some Gi */ |
1997 | } else { | 1985 | } else { |
1998 | cmd->next = 0; | 1986 | *next = 0; |
1999 | } | 1987 | } |
2000 | 1988 | ||
2001 | memcpy(PN533_FRAME_CMD_PARAMS_PTR(dev->out_frame), cmd, cmd_len); | 1989 | arg = kmalloc(sizeof(*arg), GFP_KERNEL); |
2002 | dev->out_frame->datalen += cmd_len; | 1990 | if (!arg) { |
1991 | dev_kfree_skb(skb); | ||
1992 | return -ENOMEM; | ||
1993 | } | ||
2003 | 1994 | ||
2004 | pn533_tx_frame_finish(dev->out_frame); | 1995 | *arg = !comm_mode; |
2005 | 1996 | ||
2006 | rc = pn533_send_cmd_frame_async(dev, dev->out_frame, dev->in_frame, | 1997 | rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb, |
2007 | PN533_NORMAL_FRAME_MAX_LEN, | 1998 | pn533_in_dep_link_up_complete, arg); |
2008 | pn533_in_dep_link_up_complete, cmd); | 1999 | |
2009 | if (rc < 0) | 2000 | if (rc < 0) { |
2010 | kfree(cmd); | 2001 | dev_kfree_skb(skb); |
2002 | kfree(arg); | ||
2003 | } | ||
2011 | 2004 | ||
2012 | return rc; | 2005 | return rc; |
2013 | } | 2006 | } |