18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * NFC Digital Protocol stack 48c2ecf20Sopenharmony_ci * Copyright (c) 2013, Intel Corporation. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#ifndef __DIGITAL_H 88c2ecf20Sopenharmony_ci#define __DIGITAL_H 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <net/nfc/nfc.h> 118c2ecf20Sopenharmony_ci#include <net/nfc/digital.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/crc-ccitt.h> 148c2ecf20Sopenharmony_ci#include <linux/crc-itu-t.h> 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci#define PROTOCOL_ERR(req) pr_err("%d: NFC Digital Protocol error: %s\n", \ 178c2ecf20Sopenharmony_ci __LINE__, req) 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define DIGITAL_CMD_IN_SEND 0 208c2ecf20Sopenharmony_ci#define DIGITAL_CMD_TG_SEND 1 218c2ecf20Sopenharmony_ci#define DIGITAL_CMD_TG_LISTEN 2 228c2ecf20Sopenharmony_ci#define DIGITAL_CMD_TG_LISTEN_MDAA 3 238c2ecf20Sopenharmony_ci#define DIGITAL_CMD_TG_LISTEN_MD 4 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci#define DIGITAL_MAX_HEADER_LEN 7 268c2ecf20Sopenharmony_ci#define DIGITAL_CRC_LEN 2 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define DIGITAL_SENSF_NFCID2_NFC_DEP_B1 0x01 298c2ecf20Sopenharmony_ci#define DIGITAL_SENSF_NFCID2_NFC_DEP_B2 0xFE 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#define DIGITAL_SENS_RES_NFC_DEP 0x0100 328c2ecf20Sopenharmony_ci#define DIGITAL_SEL_RES_NFC_DEP 0x40 338c2ecf20Sopenharmony_ci#define DIGITAL_SENSF_FELICA_SC 0xFFFF 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#define DIGITAL_DRV_CAPS_IN_CRC(ddev) \ 368c2ecf20Sopenharmony_ci ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC) 378c2ecf20Sopenharmony_ci#define DIGITAL_DRV_CAPS_TG_CRC(ddev) \ 388c2ecf20Sopenharmony_ci ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC) 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct digital_data_exch { 418c2ecf20Sopenharmony_ci data_exchange_cb_t cb; 428c2ecf20Sopenharmony_ci void *cb_context; 438c2ecf20Sopenharmony_ci}; 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_cistruct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev, 468c2ecf20Sopenharmony_ci unsigned int len); 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciint digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type, 498c2ecf20Sopenharmony_ci struct sk_buff *skb, struct digital_tg_mdaa_params *params, 508c2ecf20Sopenharmony_ci u16 timeout, nfc_digital_cmd_complete_t cmd_cb, 518c2ecf20Sopenharmony_ci void *cb_context); 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ciint digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param); 548c2ecf20Sopenharmony_cistatic inline int digital_in_send_cmd(struct nfc_digital_dev *ddev, 558c2ecf20Sopenharmony_ci struct sk_buff *skb, u16 timeout, 568c2ecf20Sopenharmony_ci nfc_digital_cmd_complete_t cmd_cb, 578c2ecf20Sopenharmony_ci void *cb_context) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, NULL, timeout, 608c2ecf20Sopenharmony_ci cmd_cb, cb_context); 618c2ecf20Sopenharmony_ci} 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_civoid digital_poll_next_tech(struct nfc_digital_dev *ddev); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciint digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech); 668c2ecf20Sopenharmony_ciint digital_in_send_sensb_req(struct nfc_digital_dev *ddev, u8 rf_tech); 678c2ecf20Sopenharmony_ciint digital_in_send_sensf_req(struct nfc_digital_dev *ddev, u8 rf_tech); 688c2ecf20Sopenharmony_ciint digital_in_send_iso15693_inv_req(struct nfc_digital_dev *ddev, u8 rf_tech); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciint digital_in_iso_dep_pull_sod(struct nfc_digital_dev *ddev, 718c2ecf20Sopenharmony_ci struct sk_buff *skb); 728c2ecf20Sopenharmony_ciint digital_in_iso_dep_push_sod(struct nfc_digital_dev *ddev, 738c2ecf20Sopenharmony_ci struct sk_buff *skb); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciint digital_target_found(struct nfc_digital_dev *ddev, 768c2ecf20Sopenharmony_ci struct nfc_target *target, u8 protocol); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciint digital_in_recv_mifare_res(struct sk_buff *resp); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciint digital_in_send_atr_req(struct nfc_digital_dev *ddev, 818c2ecf20Sopenharmony_ci struct nfc_target *target, __u8 comm_mode, __u8 *gb, 828c2ecf20Sopenharmony_ci size_t gb_len); 838c2ecf20Sopenharmony_ciint digital_in_send_dep_req(struct nfc_digital_dev *ddev, 848c2ecf20Sopenharmony_ci struct nfc_target *target, struct sk_buff *skb, 858c2ecf20Sopenharmony_ci struct digital_data_exch *data_exch); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciint digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param); 888c2ecf20Sopenharmony_cistatic inline int digital_tg_send_cmd(struct nfc_digital_dev *ddev, 898c2ecf20Sopenharmony_ci struct sk_buff *skb, u16 timeout, 908c2ecf20Sopenharmony_ci nfc_digital_cmd_complete_t cmd_cb, void *cb_context) 918c2ecf20Sopenharmony_ci{ 928c2ecf20Sopenharmony_ci return digital_send_cmd(ddev, DIGITAL_CMD_TG_SEND, skb, NULL, timeout, 938c2ecf20Sopenharmony_ci cmd_cb, cb_context); 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_civoid digital_tg_recv_sens_req(struct nfc_digital_dev *ddev, void *arg, 978c2ecf20Sopenharmony_ci struct sk_buff *resp); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_civoid digital_tg_recv_sensf_req(struct nfc_digital_dev *ddev, void *arg, 1008c2ecf20Sopenharmony_ci struct sk_buff *resp); 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_cistatic inline int digital_tg_listen(struct nfc_digital_dev *ddev, u16 timeout, 1038c2ecf20Sopenharmony_ci nfc_digital_cmd_complete_t cb, void *arg) 1048c2ecf20Sopenharmony_ci{ 1058c2ecf20Sopenharmony_ci return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN, NULL, NULL, 1068c2ecf20Sopenharmony_ci timeout, cb, arg); 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_civoid digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg, 1108c2ecf20Sopenharmony_ci struct sk_buff *resp); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ciint digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ciint digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech); 1158c2ecf20Sopenharmony_ciint digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech); 1168c2ecf20Sopenharmony_civoid digital_tg_recv_md_req(struct nfc_digital_dev *ddev, void *arg, 1178c2ecf20Sopenharmony_ci struct sk_buff *resp); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_citypedef u16 (*crc_func_t)(u16, const u8 *, size_t); 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define CRC_A_INIT 0x6363 1228c2ecf20Sopenharmony_ci#define CRC_B_INIT 0xFFFF 1238c2ecf20Sopenharmony_ci#define CRC_F_INIT 0x0000 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_civoid digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init, 1268c2ecf20Sopenharmony_ci u8 bitwise_inv, u8 msb_first); 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic inline void digital_skb_add_crc_a(struct sk_buff *skb) 1298c2ecf20Sopenharmony_ci{ 1308c2ecf20Sopenharmony_ci digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0); 1318c2ecf20Sopenharmony_ci} 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_cistatic inline void digital_skb_add_crc_b(struct sk_buff *skb) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0); 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic inline void digital_skb_add_crc_f(struct sk_buff *skb) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci digital_skb_add_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1); 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic inline void digital_skb_add_crc_none(struct sk_buff *skb) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci return; 1468c2ecf20Sopenharmony_ci} 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ciint digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func, 1498c2ecf20Sopenharmony_ci u16 crc_init, u8 bitwise_inv, u8 msb_first); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_cistatic inline int digital_skb_check_crc_a(struct sk_buff *skb) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0); 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cistatic inline int digital_skb_check_crc_b(struct sk_buff *skb) 1578c2ecf20Sopenharmony_ci{ 1588c2ecf20Sopenharmony_ci return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0); 1598c2ecf20Sopenharmony_ci} 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic inline int digital_skb_check_crc_f(struct sk_buff *skb) 1628c2ecf20Sopenharmony_ci{ 1638c2ecf20Sopenharmony_ci return digital_skb_check_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1); 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistatic inline int digital_skb_check_crc_none(struct sk_buff *skb) 1678c2ecf20Sopenharmony_ci{ 1688c2ecf20Sopenharmony_ci return 0; 1698c2ecf20Sopenharmony_ci} 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#endif /* __DIGITAL_H */ 172