Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  The NFC Controller Interface is the communication protocol between an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  NFC Controller (NFCC) and a Device Host (DH).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2011 Texas Instruments, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *  Written by Ilan Elias <ilane@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Acknowledgements:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  This file is based on hci_event.c, which was written
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  by Maxim Krasnyansky.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "../nfc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <net/nfc/nci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <net/nfc/nci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* Handle NCI Response packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static void nci_core_reset_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	struct nci_core_reset_rsp *rsp = (void *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	pr_debug("status 0x%x\n", rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	if (rsp->status == NCI_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		ndev->nci_ver = rsp->nci_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		pr_debug("nci_ver 0x%x, config_status 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 			 rsp->nci_ver, rsp->config_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	nci_req_complete(ndev, rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static void nci_core_init_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct nci_core_init_rsp_1 *rsp_1 = (void *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct nci_core_init_rsp_2 *rsp_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	pr_debug("status 0x%x\n", rsp_1->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	if (rsp_1->status != NCI_STATUS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (ndev->num_supported_rf_interfaces >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	    NCI_MAX_SUPPORTED_RF_INTERFACES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		ndev->num_supported_rf_interfaces =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 			NCI_MAX_SUPPORTED_RF_INTERFACES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	memcpy(ndev->supported_rf_interfaces,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	       rsp_1->supported_rf_interfaces,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	       ndev->num_supported_rf_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	ndev->max_logical_connections = rsp_2->max_logical_connections;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	ndev->max_routing_table_size =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		__le16_to_cpu(rsp_2->max_routing_table_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	ndev->max_ctrl_pkt_payload_len =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		rsp_2->max_ctrl_pkt_payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	ndev->max_size_for_large_params =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		__le16_to_cpu(rsp_2->max_size_for_large_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	ndev->manufact_id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		rsp_2->manufact_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	ndev->manufact_specific_info =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		__le32_to_cpu(rsp_2->manufact_specific_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	pr_debug("nfcc_features 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		 ndev->nfcc_features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	pr_debug("num_supported_rf_interfaces %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		 ndev->num_supported_rf_interfaces);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	pr_debug("supported_rf_interfaces[0] 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		 ndev->supported_rf_interfaces[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	pr_debug("supported_rf_interfaces[1] 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		 ndev->supported_rf_interfaces[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	pr_debug("supported_rf_interfaces[2] 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		 ndev->supported_rf_interfaces[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	pr_debug("supported_rf_interfaces[3] 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		 ndev->supported_rf_interfaces[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	pr_debug("max_logical_connections %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		 ndev->max_logical_connections);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	pr_debug("max_routing_table_size %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		 ndev->max_routing_table_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	pr_debug("max_ctrl_pkt_payload_len %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		 ndev->max_ctrl_pkt_payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	pr_debug("max_size_for_large_params %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 ndev->max_size_for_large_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	pr_debug("manufact_id 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 ndev->manufact_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	pr_debug("manufact_specific_info 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		 ndev->manufact_specific_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	nci_req_complete(ndev, rsp_1->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static void nci_core_set_config_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 					   struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	struct nci_core_set_config_rsp *rsp = (void *) skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	pr_debug("status 0x%x\n", rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	nci_req_complete(ndev, rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void nci_rf_disc_map_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				       struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static void nci_rf_disc_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct nci_conn_info    *conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	if (status == NCI_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		atomic_set(&ndev->state, NCI_DISCOVERY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		conn_info = ndev->rf_conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (!conn_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 						 sizeof(struct nci_conn_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 						 GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			if (!conn_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				status = NCI_STATUS_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			conn_info->conn_id = NCI_STATIC_RF_CONN_ID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			INIT_LIST_HEAD(&conn_info->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			list_add(&conn_info->list, &ndev->conn_info_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			ndev->rf_conn_info = conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static void nci_rf_disc_select_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* Complete the request on intf_activated_ntf or generic_error_ntf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	if (status != NCI_STATUS_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static void nci_rf_deactivate_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					 struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	/* If target was active, complete the request only in deactivate_ntf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if ((status != NCI_STATUS_OK) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	    (atomic_read(&ndev->state) != NCI_POLL_ACTIVE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		nci_clear_target_list(ndev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		atomic_set(&ndev->state, NCI_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void nci_nfcee_discover_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	struct nci_nfcee_discover_rsp *discover_rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (skb->len != 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		nci_req_complete(ndev, NCI_STATUS_NFCEE_PROTOCOL_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	discover_rsp = (struct nci_nfcee_discover_rsp *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (discover_rsp->status != NCI_STATUS_OK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	    discover_rsp->num_nfcee == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		nci_req_complete(ndev, discover_rsp->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static void nci_nfcee_mode_set_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					  struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static void nci_core_conn_create_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 					    struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct nci_conn_info *conn_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct nci_core_conn_create_rsp *rsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (status == NCI_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		rsp = (struct nci_core_conn_create_rsp *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		conn_info = devm_kzalloc(&ndev->nfc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 					 sizeof(*conn_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		if (!conn_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			status = NCI_STATUS_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			goto exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		conn_info->dest_params = devm_kzalloc(&ndev->nfc_dev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 						sizeof(struct dest_spec_params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 						GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		if (!conn_info->dest_params) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 			status = NCI_STATUS_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			goto free_conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		conn_info->dest_type = ndev->cur_dest_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		conn_info->dest_params->id = ndev->cur_params.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		conn_info->dest_params->protocol = ndev->cur_params.protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		conn_info->conn_id = rsp->conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		/* Note: data_exchange_cb and data_exchange_cb_context need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		 * be specify out of nci_core_conn_create_rsp_packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		INIT_LIST_HEAD(&conn_info->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		list_add(&conn_info->list, &ndev->conn_info_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		if (ndev->cur_params.id == ndev->hci_dev->nfcee_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			ndev->hci_dev->conn_info = conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		conn_info->conn_id = rsp->conn_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		conn_info->max_pkt_payload_len = rsp->max_ctrl_pkt_payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		atomic_set(&conn_info->credits_cnt, rsp->credits_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) free_conn_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (status == NCI_STATUS_REJECTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		devm_kfree(&ndev->nfc_dev->dev, conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static void nci_core_conn_close_rsp_packet(struct nci_dev *ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 					   struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct nci_conn_info *conn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	__u8 status = skb->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	pr_debug("status 0x%x\n", status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	if (status == NCI_STATUS_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		conn_info = nci_get_conn_info_by_conn_id(ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 							 ndev->cur_conn_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		if (conn_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			list_del(&conn_info->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			if (conn_info == ndev->rf_conn_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				ndev->rf_conn_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			devm_kfree(&ndev->nfc_dev->dev, conn_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	nci_req_complete(ndev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) void nci_rsp_packet(struct nci_dev *ndev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	__u16 rsp_opcode = nci_opcode(skb->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	/* we got a rsp, stop the cmd timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	del_timer(&ndev->cmd_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	pr_debug("NCI RX: MT=rsp, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		 nci_pbf(skb->data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		 nci_opcode_gid(rsp_opcode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		 nci_opcode_oid(rsp_opcode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		 nci_plen(skb->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	/* strip the nci control header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	skb_pull(skb, NCI_CTRL_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	if (nci_opcode_gid(rsp_opcode) == NCI_GID_PROPRIETARY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (nci_prop_rsp_packet(ndev, rsp_opcode, skb) == -ENOTSUPP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			pr_err("unsupported rsp opcode 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 			       rsp_opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		goto end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	switch (rsp_opcode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	case NCI_OP_CORE_RESET_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		nci_core_reset_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	case NCI_OP_CORE_INIT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		nci_core_init_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	case NCI_OP_CORE_SET_CONFIG_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		nci_core_set_config_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	case NCI_OP_CORE_CONN_CREATE_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		nci_core_conn_create_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	case NCI_OP_CORE_CONN_CLOSE_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		nci_core_conn_close_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	case NCI_OP_RF_DISCOVER_MAP_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		nci_rf_disc_map_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	case NCI_OP_RF_DISCOVER_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		nci_rf_disc_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	case NCI_OP_RF_DISCOVER_SELECT_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		nci_rf_disc_select_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	case NCI_OP_RF_DEACTIVATE_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		nci_rf_deactivate_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	case NCI_OP_NFCEE_DISCOVER_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		nci_nfcee_discover_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	case NCI_OP_NFCEE_MODE_SET_RSP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		nci_nfcee_mode_set_rsp_packet(ndev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		pr_err("unknown rsp opcode 0x%x\n", rsp_opcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	nci_core_rsp_packet(ndev, rsp_opcode, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	/* trigger the next cmd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	atomic_set(&ndev->cmd_cnt, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (!skb_queue_empty(&ndev->cmd_q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		queue_work(ndev->cmd_wq, &ndev->cmd_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }