• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010-2021 NXP
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  * Internal Primitives (Functions + Variables) used for Firmware Download
19  */
20 #ifndef PHDNLDNFC_INTERNAL_H
21 #define PHDNLDNFC_INTERNAL_H
22 
23 #include <phDnldNfc.h>
24 #include <phDnldNfc_Cmd.h>
25 #include <phDnldNfc_Status.h>
26 
27 #define PHDNLDNFC_CMDRESP_MAX_BUFF_SIZE_SNXXX (0x22AU)
28 #define PHDNLDNFC_CMDRESP_MAX_BUFF_SIZE_PN557 (0x100U)
29 
30 /* DL Host Short Frame Buffer Size for pipelined WRITE RSP */
31 #define PHDNLDNFC_WRITERSP_BUFF_SIZE (0x08U)
32 
33 /* DL Host Frame Buffer Header Length */
34 #define PHDNLDNFC_FRAME_HDR_LEN (0x02U)
35 /* DL Host Frame Buffer CRC Length */
36 #define PHDNLDNFC_FRAME_CRC_LEN (PHDNLDNFC_FRAME_HDR_LEN)
37 #define PHDNLDNFC_FRAME_ID_LEN (0x01U) /* Length of Cmd Id */
38 
39 /* size of EEPROM/Flash address */
40 #define PHDNLDNFC_EEFL_ADDR_SIZE (0x03U)
41 /* 2 Byte size of data */
42 #define PHDNLDNFC_DATA_SIZE (PHDNLDNFC_FRAME_HDR_LEN)
43 
44 /* Start of EEPROM address for log */
45 #define PHDNLDNFC_EEPROM_LOG_START_ADDR (0x201F80U)
46 /* End of EEPROM address for log */
47 #define PHDNLDNFC_EEPROM_LOG_END_ADDR (0x201FBFU)
48 
49 #define PHDNLDNFC_MAX_LOG_SIZE \
50   ((PHDNLDNFC_EEPROM_LOG_END_ADDR - PHDNLDNFC_EEPROM_LOG_START_ADDR) + 1)
51 
52 /*
53  * Enum definition contains Download Event Types
54  */
55 typedef enum phDnldNfc_Event {
56   phDnldNfc_EventInvalid = 0x00, /*Invalid Event Value*/
57   phDnldNfc_EventReset,          /* Reset event */
58   phDnldNfc_EventGetVer,         /* Get Version event*/
59   phDnldNfc_EventWrite,          /* Write event*/
60   phDnldNfc_EventRead,           /* Read event*/
61   phDnldNfc_EventIntegChk,       /* Integrity Check event*/
62   phDnldNfc_EventGetSesnSt,      /* Get Session State event*/
63   phDnldNfc_EventLog,            /* Log event*/
64   phDnldNfc_EventForce,          /* Force event*/
65   phDnldNfc_EventRaw, /* Raw Req/Rsp event,used currently for sending NCI RESET
66                          cmd */
67   phDnldNfc_EVENT_INT_MAX /* Max Event Count*/
68 } phDnldNfc_Event_t;
69 
70 /*
71  * Enum definition contains Download Handler states for each event requested
72  */
73 typedef enum phDnldNfc_State {
74   phDnldNfc_StateInit = 0x00, /* Handler init state */
75   phDnldNfc_StateSend,        /* Send frame to NFCC state */
76   phDnldNfc_StateRecv,        /* Recv Send complete State */
77   phDnldNfc_StateTimer, /* State to stop prev set timer on Recv or handle timed
78                            out scenario */
79   phDnldNfc_StateResponse,  /* Process response from NFCC state */
80   phDnldNfc_StatePipelined, /* Write requests to be pipelined state */
81   phDnldNfc_StateInvalid    /* Invalid Handler state */
82 } phDnldNfc_State_t;
83 
84 /*
85  * Enum definition contains Download Handler Transition
86  */
87 typedef enum phDnldNfc_Transition {
88   phDnldNfc_TransitionIdle =
89       0x00, /* Handler in Idle state - No Download in progress */
90   phDnldNfc_TransitionBusy,   /* Handler is busy processing download request */
91   phDnldNfc_TransitionInvalid /* Invalid Handler Transition */
92 } phDnldNfc_Transition_t;
93 
94 /*
95  * Enum definition contains the Frame input type for CmdId in process
96  */
97 typedef enum {
98   phDnldNfc_FTNone = 0, /* input type None */
99   phDnldNfc_ChkIntg, /* user eeprom offset & len to be added for Check Integrity
100                         Request */
101   phDnldNfc_FTWrite, /* Frame inputs for Write request */
102   phDnldNfc_FTLog,   /* Frame inputs for Log request */
103   phDnldNfc_FTForce, /* Frame input for Force cmd request */
104   phDnldNfc_FTRead,  /* Addr input required for read request */
105   phDnldNfc_FTRaw    /* Raw Req/Rsp type */
106 } phDnldNfc_FrameInputType_t;
107 
108 /*
109  * Enum definition contains Firmware file format
110  */
111 typedef enum phDnldNfc_FwFormat {
112   FW_FORMAT_UNKNOWN = 0x00,
113   FW_FORMAT_SO = 0x01,
114   FW_FORMAT_BIN = 0x02,
115   FW_FORMAT_ARRAY = 0x03,
116 } phDnldNfc_FwFormat_t;
117 
118 /*
119  * Contains Host Frame Buffer information.
120  */
121 typedef struct phDnldNfc_FrameInfo {
122   uint16_t dwSendlength; /* length of the payload  */
123   uint8_t aFrameBuff[PHDNLDNFC_CMDRESP_MAX_BUFF_SIZE_SNXXX]; /* Buffer to store
124                                                           command that needs to
125                                                           be sent*/
126 } phDnldNfc_FrameInfo_t,
127     *pphDnldNfc_FrameInfo_t; /* pointer to #phDnldNfc_FrameInfo_t */
128 
129 /*
130  * Frame Input Type & Value for CmdId in Process
131  */
132 typedef struct phDnldNfc_FrameInput {
133   phDnldNfc_FrameInputType_t
134       Type;        /* Type of frame input required for current cmd in process */
135   uint32_t dwAddr; /* Address value required for Read/Write Cmd*/
136 } phDnldNfc_FrameInput_t,
137     *pphDnldNfc_FrameInput_t; /* pointer to #phDnldNfc_FrameInput_t */
138 
139 /*
140  * Context for the response timeout
141  */
142 typedef struct phDnldNfc_RspTimerInfo {
143   uint32_t dwRspTimerId;     /* Timer for Core to handle response */
144   uint8_t TimerStatus;       /* 0 = Timer not running 1 = timer running*/
145   NFCSTATUS wTimerExpStatus; /* Holds the status code on timer expiry */
146   uint16_t rspTimeout;       /*FW download rsp timeout value*/
147 } phDnldNfc_RspTimerInfo_t;
148 
149 /*
150  * Read/Write Processing Info
151  */
152 typedef struct phDnldNfc_RWInfo {
153   uint32_t dwAddr;    /* current Addr updated for read/write */
154   uint32_t wOffset;   /* current offset within the user buffer to read/write */
155   uint32_t wRemBytes; /* Remaining bytes to read/write */
156   uint16_t wRemChunkBytes; /* Remaining bytes within the chunked frame */
157   uint16_t wRWPldSize;     /* Size of the read/write payload per transaction */
158   uint16_t wBytesToSendRecv; /* Num of Bytes being written/read currently */
159   uint16_t wBytesRead;       /* Bytes read from read cmd currently */
160   bool_t bFramesSegmented;   /* Flag to indicate if Read/Write frames are
161                                 segmented */
162   bool_t bFirstWrReq; /* Flag to indicate if this is the first write frame being
163                          sent */
164   bool_t
165       bFirstChunkResp; /* Flag to indicate if we got the first chunk response */
166 } phDnldNfc_RWInfo_t, *pphDnldNfc_RWInfo_t; /* pointer to #phDnldNfc_RWInfo_t */
167 
168 /*
169  * Download context structure
170  */
171 typedef struct phDnldNfc_DlContext {
172   const uint8_t* nxp_nfc_fw; /* Pointer to firmware version from image */
173   const uint8_t*
174       nxp_nfc_fwp; /* Pointer to firmware version from get_version cmd */
175   uint32_t nxp_nfc_fwp_len; /* Length of firmware image length */
176   uint32_t nxp_nfc_fw_len;  /* Firmware image length */
177   uint16_t nxp_i2c_fragment_len;
178   bool_t bResendLastFrame;  /* Flag to resend the last write frame after MEM_BSY
179                                status */
180   phDnldNfc_Transition_t
181       tDnldInProgress; /* Flag to indicate if download request is ongoing */
182   phDnldNfc_Event_t tCurrEvent; /* Current event being processed */
183   phDnldNfc_State_t tCurrState; /* Current state being processed */
184   pphDnldNfc_RspCb_t UserCb;    /* Upper layer call back function */
185   void* UserCtxt;               /* Pointer to upper layer context */
186   phDnldNfc_Buff_t tUserData;   /* Data buffer provided by caller */
187   phDnldNfc_Buff_t
188       tRspBuffInfo; /* Buffer to store payload field of the received response*/
189   phDnldNfc_FrameInfo_t tCmdRspFrameInfo; /* Buffer to hold the cmd/resp frame
190                                              except pipeline write */
191   phDnldNfc_FrameInfo_t
192       tPipeLineWrFrameInfo; /* Buffer to hold the pipelined write frame */
193   NFCSTATUS
194   wCmdSendStatus; /* Holds the status of cmd request made to cmd handler */
195   phDnldNfc_CmdId_t tCmdId; /* Cmd Id of the currently processed cmd */
196   phDnldNfc_FrameInput_t
197       FrameInp; /* input value required for current cmd in process */
198   phDnldNfc_RspTimerInfo_t
199       TimerInfo;              /* Timer context handled into download context*/
200   phDnldNfc_Buff_t tTKey;     /* Default Transport Key provided by caller */
201   phDnldNfc_RWInfo_t tRWInfo; /* Read/Write segmented frame info */
202   phDnldNfc_Status_t tLastStatus; /* saved status to distinguish signature or
203                                      pltform recovery */
204   phDnldNfc_FwFormat_t FwFormat;  /*FW file format either lib or bin*/
205 } phDnldNfc_DlContext_t,
206     *pphDnldNfc_DlContext_t; /* pointer to #phDnldNfc_DlContext_t structure */
207 
208 /* The phDnldNfc_CmdHandler function declaration */
209 extern NFCSTATUS phDnldNfc_CmdHandler(void* pContext,
210                                       phDnldNfc_Event_t TrigEvent);
211 
212 #endif /* PHDNLDNFC_INTERNAL_H */
213