/* * NFC Digital Protocol stack * Copyright (c) 2013, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * */ #define pr_fmt(fmt) "digital: %s: " fmt, __func__ #include "digital.h" #define DIGITAL_NFC_DEP_N_RETRY_NACK 2 #define DIGITAL_NFC_DEP_N_RETRY_ATN 2 #define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4 #define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5 #define DIGITAL_NFC_DEP_NFCA_SOD_SB 0xF0 #define DIGITAL_CMD_ATR_REQ 0x00 #define DIGITAL_CMD_ATR_RES 0x01 #define DIGITAL_CMD_PSL_REQ 0x04 #define DIGITAL_CMD_PSL_RES 0x05 #define DIGITAL_CMD_DEP_REQ 0x06 #define DIGITAL_CMD_DEP_RES 0x07 #define DIGITAL_ATR_REQ_MIN_SIZE 16 #define DIGITAL_ATR_REQ_MAX_SIZE 64 #define DIGITAL_DID_MAX 14 #define DIGITAL_PAYLOAD_SIZE_MAX 254 #define DIGITAL_PAYLOAD_BITS_TO_PP(s) (((s) & 0x3) << 4) #define DIGITAL_PAYLOAD_PP_TO_BITS(s) (((s) >> 4) & 0x3) #define DIGITAL_PAYLOAD_BITS_TO_FSL(s) ((s) & 0x3) #define DIGITAL_PAYLOAD_FSL_TO_BITS(s) ((s) & 0x3) #define DIGITAL_GB_BIT 0x02 #define DIGITAL_NFC_DEP_REQ_RES_HEADROOM 2 /* SoD: [SB (NFC-A)] + LEN */ #define DIGITAL_NFC_DEP_REQ_RES_TAILROOM 2 /* EoD: 2-byte CRC */ #define DIGITAL_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0) #define DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT 0x10 #define DIGITAL_NFC_DEP_PFB_MI_BIT 0x10 #define DIGITAL_NFC_DEP_PFB_NACK_BIT 0x10 #define DIGITAL_NFC_DEP_PFB_DID_BIT 0x04 #define DIGITAL_NFC_DEP_PFB_IS_TIMEOUT(pfb) \ ((pfb) & DIGITAL_NFC_DEP_PFB_TIMEOUT_BIT) #define DIGITAL_NFC_DEP_MI_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_MI_BIT) #define DIGITAL_NFC_DEP_NACK_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_NACK_BIT) #define DIGITAL_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08) #define DIGITAL_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & DIGITAL_NFC_DEP_PFB_DID_BIT) #define DIGITAL_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03) #define DIGITAL_NFC_DEP_PFB_I_PDU 0x00 #define DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU 0x40 #define DIGITAL_NFC_DEP_PFB_SUPERVISOR_PDU 0x80 struct digital_atr_req { u8 dir; u8 cmd; u8 nfcid3[10]; u8 did; u8 bs; u8 br; u8 pp; u8 gb[0]; } __packed; struct digital_atr_res { u8 dir; u8 cmd; u8 nfcid3[10]; u8 did; u8 bs; u8 br; u8 to; u8 pp; u8 gb[0]; } __packed; struct digital_psl_req { u8 dir; u8 cmd; u8 did; u8 brs; u8 fsl; } __packed; struct digital_psl_res { u8 dir; u8 cmd; u8 did; } __packed; struct digital_dep_req_res { u8 dir; u8 cmd; u8 pfb; } __packed; static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp); static void digital_tg_recv_dep_req(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp); static const u8 digital_payload_bits_map[4] = { [0] = 64, [1] = 128, [2] = 192, [3] = 254 }; static u8 digital_payload_bits_to_size(u8 payload_bits) { if (payload_bits >= ARRAY_SIZE(digital_payload_bits_map)) return 0; return digital_payload_bits_map[payload_bits]; } static u8 digital_payload_size_to_bits(u8 payload_size) { int i; for (i = 0; i < ARRAY_SIZE(digital_payload_bits_map); i++) if (digital_payload_bits_map[i] == payload_size) return i; return 0xff; } static void digital_skb_push_dep_sod(struct nfc_digital_dev *ddev, struct sk_buff *skb) { skb_push(skb, sizeof(u8)); skb->data[0] = skb->len; if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) *skb_push(skb, sizeof(u8)) = DIGITAL_NFC_DEP_NFCA_SOD_SB; } static int digital_skb_pull_dep_sod(struct nfc_digital_dev *ddev, struct sk_buff *skb) { u8 size; if (skb->len < 2) return -EIO; if (ddev->curr_rf_tech == NFC_DIGITAL_RF_TECH_106A) skb_pull(skb, sizeof(u8)); size = skb->data[0]; if (size != skb->len) return -EIO; skb_pull(skb, sizeof(u8)); return 0; } static struct sk_buff * digital_send_dep_data_prep(struct nfc_digital_dev *ddev, struct sk_buff *skb, struct digital_dep_req_res *dep_req_res, struct digital_data_exch *data_exch) { struct sk_buff *new_skb; if (skb->len > ddev->remote_payload_max) { dep_req_res->pfb |= DIGITAL_NFC_DEP_PFB_MI_BIT; new_skb = digital_skb_alloc(ddev, ddev->remote_payload_max); if (!new_skb) { kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; return ERR_PTR(-ENOMEM); } skb_reserve(new_skb, ddev->tx_headroom + NFC_HEADER_SIZE + DIGITAL_NFC_DEP_REQ_RES_HEADROOM); memcpy(skb_put(new_skb, ddev->remote_payload_max), skb->data, ddev->remote_payload_max); skb_pull(skb, ddev->remote_payload_max); ddev->chaining_skb = skb; ddev->data_exch = data_exch; } else { ddev->chaining_skb = NULL; new_skb = skb; } return new_skb; } static struct sk_buff * digital_recv_dep_data_gather(struct nfc_digital_dev *ddev, u8 pfb, struct sk_buff *resp, int (*send_ack)(struct nfc_digital_dev *ddev, struct digital_data_exch *data_exch), struct digital_data_exch *data_exch) { struct sk_buff *new_skb; int rc; if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb) && (!ddev->chaining_skb)) { ddev->chaining_skb = nfc_alloc_recv_skb(8 * ddev->local_payload_max, GFP_KERNEL); if (!ddev->chaining_skb) { rc = -ENOMEM; goto error; } } if (ddev->chaining_skb) { if (resp->len > skb_tailroom(ddev->chaining_skb)) { new_skb = skb_copy_expand(ddev->chaining_skb, skb_headroom( ddev->chaining_skb), 8 * ddev->local_payload_max, GFP_KERNEL); if (!new_skb) { rc = -ENOMEM; goto error; } kfree_skb(ddev->chaining_skb); ddev->chaining_skb = new_skb; } memcpy(skb_put(ddev->chaining_skb, resp->len), resp->data, resp->len); kfree_skb(resp); resp = NULL; if (DIGITAL_NFC_DEP_MI_BIT_SET(pfb)) { rc = send_ack(ddev, data_exch); if (rc) goto error; return NULL; } resp = ddev->chaining_skb; ddev->chaining_skb = NULL; } return resp; error: kfree_skb(resp); kfree_skb(ddev->chaining_skb); ddev->chaining_skb = NULL; return ERR_PTR(rc); } static void digital_in_recv_psl_res(struct nfc_digital_dev *ddev, void *arg, struct sk_buff *resp) { struct nfc_target *target = arg; struct digital_psl_res *psl_res; int rc; if (IS_ERR(resp)) { rc = PTR_ERR(resp); resp = NULL; goto exit; } rc = ddev->skb_check_crc(resp); if (rc) { PROTOCOL_ERR("14.4.1.6"); goto exit; } rc = digital_skb_pull_dep_sod(ddev, resp); if (rc) { PROTOCOL_ERR("14.4.1.2"); goto exit; } psl_res = (struct digital_psl_res *)resp->data; if ((res
# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#;
nodes:
-
name: "trafficgen_1"
role: TrafficGen
ip: 1.1.1.1
user: "root"
ssh_port: "22"
password: "r00t"
key_filename: ""
interfaces:
xe0:
vpci: "0000:05:00.0"
local_mac: "68:05:ca:30:3d:50"
driver: "i40e"
local_ip: "152.16.100.19"
netmask: "255.255.255.0"
dpdk_port_num: 0
xe1:
vpci: "0000:05:00.1"
local_mac: "68:05:ca:30:3d:51"
driver: "i40e"
local_ip: "152.16.40.19"
netmask: "255.255.255.0"
dpdk_port_num: 1
-
name: "vnf"
role: VNF
ip: 1.1.1.2
user: "root"
ssh_port: "22"
password: "r00t"
key_filename: ""
interfaces:
xe0:
vpci: "0000:05:00.0"
local_mac: "68:05:ca:30:3c:68"
driver: "i40e"
local_ip: "152.16.100.21"
netmask: "255.255.255.0"
dpdk_port_num: 0
xe1:
vpci: "0000:05:00.1"
local_mac: "68:05:ca:30:3c:69"
driver: "i40e"
local_ip: "152.16.40.21"
netmask: "255.255.255.0"
dpdk_port_num: 1
routing_table:
- network: "152.16.100.20"
netmask: "255.255.255.0"
gateway: "152.16.100.20"
if: "xe0"
- network: "152.16.40.20"
netmask: "255.255.255.0"
gateway: "152.16.40.20"
if: "xe1"
nd_route_tbl:
- network: "0064:ff9b:0:0:0:0:9810:6414"
netmask: "112"
gateway: "0064:ff9b:0:0:0:0:9810:6414"
if: "xe0"
- network: "0064:ff9b:0:0:0:0:9810:2814"
netmask: "112"
gateway: "0064:ff9b:0:0:0:0:9810:2814"
if: "xe1"