CryptoAuthLib
Microchip CryptoAuthentication Library
atca_iface.h
Go to the documentation of this file.
1 
29 #ifndef ATCA_IFACE_H
30 #define ATCA_IFACE_H
31 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #include "atca_command.h"
43 
44 typedef enum
45 {
52  // additional physical interface types here
55 
56 /* ATCAIfaceCfg is a mediator object between a completely abstract notion of a
57  physical interface and an actual physical interface.
58 
59  The main purpose of it is to keep hardware specifics from bleeding into the
60  higher levels - hardware specifics could include things like framework
61  specific items (ASF SERCOM) vs a non-Microchip I2C library constant that
62  defines an I2C port. But I2C has roughly the same parameters regardless of
63  architecture and framework.
64  */
65 
66 typedef struct
67 {
68 
69  ATCAIfaceType iface_type; // active iface - how to interpret the union below
70  ATCADeviceType devtype; // explicit device type
71 
72  union // each instance of an iface cfg defines a single type of interface
73  {
74  struct ATCAI2C
75  {
76  uint8_t slave_address; // 8-bit slave address
77  uint8_t bus; // logical i2c bus number, 0-based - HAL will map this to a pin pair for SDA SCL
78  uint32_t baud; // typically 400000
79  } atcai2c;
80 
81  struct ATCASWI
82  {
83  uint8_t bus; // logical SWI bus - HAL will map this to a pin or uart port
84  } atcaswi;
85 
86  struct ATCAUART
87  {
88  int port; // logic port number
89  uint32_t baud; // typically 115200
90  uint8_t wordsize; // usually 8
91  uint8_t parity; // 0 == even, 1 == odd, 2 == none
92  uint8_t stopbits; // 0,1,2
93  } atcauart;
94 
95  struct ATCAHID
96  {
97  int idx; // HID enumeration index
98  uint32_t vid; // Vendor ID of kit (0x03EB for CK101)
99  uint32_t pid; // Product ID of kit (0x2312 for CK101)
100  uint32_t packetsize; // Size of the USB packet
101  uint8_t guid[16]; // The GUID for this HID device
102  } atcahid;
103 
104  struct ATCACUSTOM
105  {
106  ATCA_STATUS (*halinit)(void *hal, void *cfg);
107  ATCA_STATUS (*halpostinit)(void *iface);
108  ATCA_STATUS (*halsend)(void *iface, uint8_t *txdata, int txlength);
109  ATCA_STATUS (*halreceive)(void *iface, uint8_t* rxdata, uint16_t* rxlength);
110  ATCA_STATUS (*halwake)(void *iface);
111  ATCA_STATUS (*halidle)(void *iface);
112  ATCA_STATUS (*halsleep)(void *iface);
113  ATCA_STATUS (*halrelease)(void* hal_data);
114  } atcacustom;
115 
116  };
117 
118  uint16_t wake_delay; // microseconds of tWHI + tWLO which varies based on chip type
119  int rx_retries; // the number of retries to attempt for receiving bytes
120  void * cfg_data; // opaque data used by HAL in device discovery
121 } ATCAIfaceCfg;
122 typedef struct atca_iface * ATCAIface;
123 
124 
130 {
132  ATCAIfaceCfg *mIfaceCFG; // points to previous defined/given Cfg object, caller manages this
133 
134  ATCA_STATUS (*atinit)(void *hal, ATCAIfaceCfg *);
136  ATCA_STATUS (*atsend)(ATCAIface hal, uint8_t *txdata, int txlength);
137  ATCA_STATUS (*atreceive)(ATCAIface hal, uint8_t *rxdata, uint16_t *rxlength);
141 
142  // treat as private
143  void *hal_data; // generic pointer used by HAL to point to architecture specific structure
144  // no ATCA object should touch this except HAL, HAL manages this pointer and memory it points to
145 };
146 
150 void deleteATCAIface(ATCAIface *ca_iface);
151 
152 // IFace methods
153 ATCA_STATUS atinit(ATCAIface ca_iface);
155 ATCA_STATUS atsend(ATCAIface ca_iface, uint8_t *txdata, int txlength);
156 ATCA_STATUS atreceive(ATCAIface ca_iface, uint8_t *rxdata, uint16_t *rxlength);
157 ATCA_STATUS atwake(ATCAIface ca_iface);
158 ATCA_STATUS atidle(ATCAIface ca_iface);
159 ATCA_STATUS atsleep(ATCAIface ca_iface);
160 
161 // accessors
163 void* atgetifacehaldat(ATCAIface ca_iface);
164 
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif
171 
172 
173 
ATCAIfaceType mType
Definition: atca_iface.h:131
Definition: hal_all_platforms_kit_hidapi.h:48
Definition: atca_iface.h:66
ATCA_STATUS atwake(ATCAIface ca_iface)
Wakes up the device by calling intermediate HAL wrapper function. If using the basic API...
Definition: atca_iface.c:156
uint8_t slave_address
Definition: atca_iface.h:76
Microchip Crypto Auth device command object - this is a command builder only, it does not send the co...
ATCAIfaceType iface_type
Definition: atca_iface.h:69
ATCA_STATUS atreceive(ATCAIface ca_iface, uint8_t *rxdata, uint16_t *rxlength)
Receives data from the device by calling intermediate HAL wrapper function.
Definition: atca_iface.c:145
uint32_t baud
Definition: atca_iface.h:78
ATCA_STATUS
Definition: atca_status.h:41
ATCA_STATUS atsleep(ATCAIface ca_iface)
Puts the device into sleep state by calling intermediate HAL wrapper function. If using the basic API...
Definition: atca_iface.c:194
uint8_t parity
Definition: atca_iface.h:91
Definition: atca_iface.h:49
ATCAIfaceType
Definition: atca_iface.h:44
ATCA_STATUS(* atinit)(void *hal, ATCAIfaceCfg *)
Definition: atca_iface.h:134
Definition: atca_iface.h:53
void * hal_data
Definition: atca_iface.h:143
Definition: atca_iface.h:46
Definition: atca_iface.h:48
ATCA_STATUS releaseATCAIface(ATCAIface ca_iface)
Instruct the HAL driver to release any resources associated with this interface.
Definition: atca_iface.c:228
uint32_t pid
Definition: atca_iface.h:99
ATCAIfaceCfg * mIfaceCFG
Definition: atca_iface.h:132
struct atca_iface * ATCAIface
Definition: atca_iface.h:122
Definition: atca_iface.h:51
ATCAIface newATCAIface(ATCAIfaceCfg *cfg)
Constructor for ATCAIface objects.
Definition: atca_iface.c:82
ATCA_STATUS(* atidle)(ATCAIface hal)
Definition: atca_iface.h:139
ATCA_STATUS atpostinit(ATCAIface ca_iface)
void deleteATCAIface(ATCAIface *ca_iface)
Instruct the HAL driver to release any resources associated with this interface, then delete the obje...
Definition: atca_iface.c:243
ATCA_STATUS initATCAIface(ATCAIfaceCfg *cfg, ATCAIface ca_iface)
Initializer for ATCAIface objects.
Definition: atca_iface.c:56
ATCA_STATUS(* atsend)(ATCAIface hal, uint8_t *txdata, int txlength)
Definition: atca_iface.h:136
void * cfg_data
Definition: atca_iface.h:120
ATCADeviceType
The supported Device type in Cryptoauthlib library.
Definition: atca_devtypes.h:41
uint16_t wake_delay
Definition: atca_iface.h:118
int port
Definition: atca_iface.h:88
int idx
Definition: atca_iface.h:97
uint32_t packetsize
Definition: atca_iface.h:100
ATCA_STATUS atidle(ATCAIface ca_iface)
Puts the device into idle state by calling intermediate HAL wrapper function. If using the basic API...
Definition: atca_iface.c:179
ATCADeviceType devtype
Definition: atca_iface.h:70
ATCA_STATUS atinit(ATCAIface ca_iface)
Performs the HAL initialization by calling intermediate HAL wrapper function. If using the basic API...
Definition: atca_iface.c:106
int rx_retries
Definition: atca_iface.h:119
ATCA_STATUS(* atsleep)(ATCAIface hal)
Definition: atca_iface.h:140
atca_iface is the C object backing ATCAIface. See the atca_iface.h file for details on the ATCAIface ...
Definition: atca_iface.h:129
ATCAIfaceCfg * atgetifacecfg(ATCAIface ca_iface)
Returns the logical interface configuration for the device.
Definition: atca_iface.c:208
ATCA_STATUS(* atwake)(ATCAIface hal)
Definition: atca_iface.h:138
ATCA_STATUS(* atreceive)(ATCAIface hal, uint8_t *rxdata, uint16_t *rxlength)
Definition: atca_iface.h:137
ATCA_STATUS atsend(ATCAIface ca_iface, uint8_t *txdata, int txlength)
Sends the data to the device by calling intermediate HAL wrapper function.
Definition: atca_iface.c:132
Definition: atca_iface.h:50
uint32_t vid
Definition: atca_iface.h:98
uint8_t bus
Definition: atca_iface.h:77
ATCA_STATUS(* atpostinit)(ATCAIface hal)
Definition: atca_iface.h:135
Definition: atca_iface.h:47
uint8_t stopbits
Definition: atca_iface.h:92
uint8_t wordsize
Definition: atca_iface.h:90
void * atgetifacehaldat(ATCAIface ca_iface)
Returns the HAL data pointer for the device.
Definition: atca_iface.c:218