1 /*
2  *    Copyright (C) 2013 SAMSUNG S.LSI
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at:
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  *
16  *
17  */
18 
19 #ifndef __NFC_SEC_HALMSG__
20 #define __NFC_SEC_HALMSG__
21 
22 /***************************************
23  * NCI
24  ***************************************/
25 #define HAL_EVT_SIZE 1
26 #define NCI_HDR_SIZE 3
27 #define NCI_MAX_PAYLOAD 0xFF
28 #define NCI_CTRL_SIZE (NCI_HDR_SIZE + NCI_MAX_PAYLOAD)
29 
30 typedef struct {
31   uint8_t oct0;
32   uint8_t oid;
33   uint8_t len;
34   uint8_t payload[NCI_MAX_PAYLOAD];
35 } tNFC_NCI_PKT;
36 /* START [181106] Patch for supporting NCI v2.0 */
37 // [1. NCI Version Management]
38 #define NCI_VER_1_0 0x10
39 #define NCI_VER_2_0 0x20
40 /* END [181106] Patch for supporting NCI v2.0 */
41 #define NCI_MT(x) ((x)->oct0 & 0xE0)
42 #define NCI_PBF(x) ((x)->oct0 & 0x10)
43 #define NCI_GID(x) ((x)->oct0 & 0x0F)
44 #define NCI_OID(x) ((x)->oid & 0x3F)
45 #define NCI_LEN(x) ((x)->len)
46 #define NCI_PAYLOAD(x) ((x)->payload)
47 #define NCI_STATUS(x) (((x)->payload)[0])
48 #define NCI_MF_INFO_SIZE 4
49 #define NCI_MF_INFO(x) (((x)->payload) + (x)->len - NCI_MF_INFO_SIZE)
50 #define NCI_PKT_LEN(x) (NCI_HDR_SIZE + NCI_LEN(x))
51 
52 #define NCI_MT_DATA 0x00
53 #define NCI_MT_CMD 0x20
54 #define NCI_MT_RSP 0x40
55 #define NCI_MT_NTF 0x60
56 
57 #define NCI_PBF_LAST 0x00
58 #define NCI_PBF_CONTINUE 0x10
59 
60 #define NCI_GID_CORE 0x00
61 #define NCI_GID_RF_MANAGE 0x01
62 #define NCI_GID_EE_MANAGE 0x02
63 #define NCI_GID_PROP 0x0F
64 
65 #define NCI_CORE_RESET 0x00
66 #define NCI_CORE_INIT 0x01
67 
68 #define NCI_PROP_AGAIN                                     \
69   0x01 /* This prop oid is used only for N3 (sleep mode) \ \
70         */
71 #define NCI_PROP_FW_CFG 0x28
72 #define NCI_PROP_WR_RESET 0x2F
73 #define NCI_PROP_SET_SLEEP_TIME 0x1A /* Last updated value: 20160530 */
74 
75 #define SET_SLEEP_TIME_CFG 0
76 #define SET_SLEEP_TIME_ONCE 1
77 #define SET_SLEEP_TIME_FORCE 2
78 
79 #define NCI_STATUS_OK 0x00
80 #define NCI_STATUS_E_SYNTAX 0x05
81 
82 /* START [S15012201] - block flip cover in RF field */
83 #define HAL_NFC_STATUS_ERR_TRANSPORT 2
84 /* END [S15012201] - block flip cover in RF field */
85 
86 /* Response Value for Clock Setting. */
87 #define NCI_CLOCK_STATUS_SYNTAX_ERROR 0x01
88 #define NCI_CLOCK_STATUS_MISMATCHED 0x02
89 #define NCI_CLOCK_STATUS_FULL 0x03
90 /***************************************
91  * BOOTLOADER
92  ***************************************/
93 #define FW_HDR_SIZE 4
94 typedef struct {
95   uint8_t type;
96   uint8_t code;
97   uint16_t len;
98   uint8_t payload[NCI_MAX_PAYLOAD + 1];
99 } tNFC_FW_PKT;
100 #define FW_PAYLOAD(x) ((x)->payload)
101 
102 /* type */
103 typedef enum { FW_MSG_CMD = 0, FW_MSG_RSP, FW_MSG_DATA } eNFC_FW_BLTYPE;
104 
105 /***************************************
106  * HAL Message
107  ***************************************/
108 #define MSG_EVENT_SIZE 1
109 typedef struct {
110   uint8_t event;
111   union {
112     tNFC_NCI_PKT nci_packet;
113     tNFC_FW_PKT fw_packet;
114     uint8_t param[NCI_CTRL_SIZE];
115   };
116 } tNFC_HAL_MSG;
117 
118 #define HAL_EVT_OPEN 0x00
119 #define HAL_EVT_CORE_INIT 0x01
120 #define HAL_EVT_PRE_DISCOVER 0x02
121 #define HAL_EVT_WRITE 0x03
122 #define HAL_EVT_READ 0x04
123 #define HAL_EVT_CONTROL_GRANTED 0x05
124 #define HAL_EVT_TERMINATE 0x06
125 /* START - VTS */
126 #define HAL_EVT_POWER_CYCLE 0x07
127 /* END - VTS */
128 #define HAL_EVT_COMPLETE 0xF0
129 #define HAL_EVT_COMPLETE_FAILED 0xF1
130 
131 /***************************************
132  * NFC Message
133  ***************************************/
134 #define NFC_STATUS_OK 0x00
135 #define NFC_STATUS_FAILED 0x01
136 
137 #endif  //__NFC_SEC_HALMSG__
138