Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers d7a_alp.h Source File

d7a_alp.h

00001 #ifndef _D7A_ALP_H_
00002 #define _D7A_ALP_H_
00003 
00004 #define D7A_ALP_RESP_TO     (60000)
00005 
00006 #define ALP_CTRL_GROUP      0x80
00007 #define ALP_CTRL_RESP       0x40
00008 #define ALP_CTRL_OVERLOAD   0x80
00009 #define ALP_CTRL_INDIRECT   0x40
00010 #define ALP_CTRL_EOP        0x80
00011 #define ALP_CTRL_ERR        0x40
00012 
00013 #define D7A_AUTH_PROTOCOLE_TOKEN_SIZE   (8)
00014 
00015 typedef enum {
00016 //      OPCODE                      | OPERAND
00017     ALP_OPCODE_NOP          = 0,  //|   -
00018 
00019     ALP_OPCODE_F_RD_DATA    = 1,  //|  FDR
00020     ALP_OPCODE_F_RD_PROP    = 2,  //|  FID
00021 
00022     ALP_OPCODE_F_WR_DATA    = 4,  //|  FD
00023     ALP_OPCODE_F_WR_FLUSH   = 5,  //|  FD
00024     ALP_OPCODE_F_WR_PROP    = 6,  //|  FD
00025 
00026     ALP_OPCODE_QUERY        = 8,  //|   Q
00027     ALP_OPCODE_QBREAK       = 9,  //|   Q
00028     ALP_OPCODE_PERM_REQ     = 10, //|   P
00029 
00030     ALP_OPCODE_CRC_CHECK    = 11, //|  Q
00031 
00032     ALP_OPCODE_F_EXIST      = 16, //|  FID
00033     ALP_OPCODE_F_CREATE     = 17, //|  FD
00034     ALP_OPCODE_F_DELETE     = 18, //|  FID
00035     ALP_OPCODE_F_RESTORE    = 19, //|  FID
00036     ALP_OPCODE_F_FLUSH      = 20, //|  FID
00037     ALP_OPCODE_F_OPEN       = 21, //|  FID
00038     ALP_OPCODE_F_CLOSE      = 22, //|  FID
00039     ALP_OPCODE_F_COPY       = 23, //|  2xFID
00040     ALP_OPCODE_F_EXECUTE    = 31, //|  FID
00041 
00042     ALP_OPCODE_RSP_F_DATA   = 32, //|  FD
00043     ALP_OPCODE_RSP_F_PROP   = 33, //|  FH
00044     ALP_OPCODE_RSP_STATUS   = 34, //|  S
00045     ALP_OPCODE_RSP_ISTATUS  = ALP_OPCODE_RSP_STATUS + (1 << 6), //|   SI
00046     ALP_OPCODE_RSP_TAG      = 35, //|  PID
00047     ALP_OPCODE_RSP_EOPTAG   = ALP_OPCODE_RSP_TAG + (2 << 6), //|   PID
00048     ALP_OPCODE_RSP_ERRTAG   = ALP_OPCODE_RSP_TAG + (1 << 6), //|   PID
00049 
00050     ALP_OPCODE_CHUNK        = 48, //|  -
00051     ALP_OPCODE_LOGIC        = 49, //|  -
00052     ALP_OPCODE_FORWARD      = 50, //|  I
00053     ALP_OPCODE_IFORWARD     = 51, //|  IFID
00054     ALP_OPCODE_TAG          = 52, //|  PID
00055 
00056     ALP_OPCODE_EXT          = 63, //|  RFU
00057 
00058     // Modifiers
00059     ALP_OPCODE_RESP         = 0x40,
00060     ALP_OPCODE_GROUP        = 0x80,
00061 
00062     ALP_OPCODE_ERR          = 0x40,
00063     ALP_OPCODE_EOP          = 0x80,
00064 
00065     ALP_OPCODE_INDIRECT     = 0x40,
00066     ALP_OPCODE_OVERLOAD     = 0x80,
00067 
00068 } alp_opcodes_t;
00069 
00070 
00071 typedef enum {
00072     ALP_RESP_TYPE_UNKNOWN = 0,
00073     ALP_RESP_TYPE_F_DATA  = ALP_OPCODE_RSP_F_DATA,
00074     ALP_RESP_TYPE_F_PROP  = ALP_OPCODE_RSP_F_PROP,
00075     ALP_RESP_TYPE_ISTATUS = ALP_OPCODE_RSP_ISTATUS,
00076     ALP_RESP_TYPE_STATUS  = ALP_OPCODE_RSP_STATUS,
00077     ALP_RESP_TYPE_TAG     = ALP_OPCODE_RSP_TAG,
00078 } alp_resp_type_t;
00079 
00080 
00081 
00082 typedef struct {
00083     uint8_t              type;
00084     uint8_t*             data;   // data
00085     union
00086     {
00087         struct {
00088             uint32_t             length;
00089             uint32_t             offset;
00090             uint8_t              fid;
00091         } f_data;
00092         struct {
00093             uint32_t             length;
00094             uint32_t             offset;
00095             uint8_t              fid;
00096         } f_prop;
00097         struct {
00098             uint8_t              code;
00099             uint8_t              id; // Action ID
00100         } status;
00101         struct {
00102             uint32_t             length;
00103             uint8_t              type;
00104         } itf;
00105         struct {
00106             uint8_t              id;
00107             uint8_t              eop;
00108             uint8_t              err;
00109         } tag;
00110     } meta;
00111 } alp_uns_resp_parsed_t;
00112 
00113 TYPEDEF_STRUCT_PACKED 
00114 {
00115     uint8_t aid;
00116     int8_t status;
00117 } d7a_alp_rsp_status_t;
00118 
00119 #define NO_TAG      (-1)
00120 TYPEDEF_STRUCT_PACKED 
00121 {
00122     int16_t tag;
00123     bool eop;
00124     d7a_msg_t* msg;
00125 } d7a_alp_rsp_t;
00126 
00127 
00128 
00129 // =======================================================================
00130 // d7a_ch_header_t
00131 // -----------------------------------------------------------------------
00132 /// Bitfield structure of the channel identifier
00133 // =======================================================================
00134 typedef union
00135 {
00136     // bit access fields
00137     struct {
00138         /// Coding scheme
00139         uint8_t cs   : 2;
00140         /// Channel Class
00141         uint8_t cl   : 2;
00142         /// Channel Band
00143         uint8_t band : 3;
00144         /// RFU
00145         uint8_t rfu  : 1;
00146     } bf;
00147 
00148     // byte access
00149     uint8_t byte;
00150 
00151 } d7a_ch_header_t;
00152 
00153 // =======================================================================
00154 // d7a_sp_status_t
00155 // -----------------------------------------------------------------------
00156 /// Bitfield structure of the D7ASP segment status byte
00157 // =======================================================================
00158 typedef union
00159 {
00160     // bit access fields
00161     struct {
00162         /// RFU
00163         uint8_t rfu          : 4;
00164         /// Identifier type of the received segment
00165         uint8_t idf          : 2; 
00166         /// Current seqnum was already received
00167         uint8_t retry        : 1;
00168         /// There are not received seqnums anterior to the current seqnum
00169         uint8_t missed       : 1;
00170     } bf;
00171 
00172     // byte access
00173     uint8_t byte;
00174 
00175 } d7a_sp_status_t;
00176 
00177 // =======================================================================
00178 // d7a_nwl_security_t
00179 // -----------------------------------------------------------------------
00180 /// NWL Security File structure
00181 // =======================================================================
00182 TYPEDEF_STRUCT_PACKED
00183 {
00184     /// Key counter
00185     uint8_t key_counter;
00186     /// Frame counter
00187     uint32_t frame_counter;
00188 
00189 } d7a_nwl_security_t;
00190 
00191 
00192 // =======================================================================
00193 // d7a_sp_res_t
00194 // -----------------------------------------------------------------------
00195 /// D7A specific segment metadata
00196 // =======================================================================
00197 TYPEDEF_STRUCT_PACKED
00198 {
00199     /// channel header
00200     d7a_ch_header_t header;    
00201     /// channel index
00202     uint16_t idx;
00203     /// RSSI in -dBm
00204     int8_t  rxlev;
00205     /// Link budget in dB
00206     int8_t  lb;
00207     /// Target RXLEV in -dBm
00208     int8_t  target_rxlev;
00209     /// D7ASP status
00210     d7a_sp_status_t status;
00211     /// D7ASP Token
00212     uint8_t  token;
00213     /// D7ASP Sequence number
00214     uint8_t  seq;
00215     /// Response timeout
00216     uint32_t resp_to;
00217     /// Addressee
00218     d7a_addressee_t addressee;
00219     /// NLS security state (optional)
00220     d7a_nwl_security_t nls_state;
00221 
00222 } d7a_sp_res_t;
00223 
00224 
00225 
00226 d7a_errors_t d7a_alp_open(UnsolicitedMsgFunction uns_msg);
00227 d7a_errors_t d7a_alp_close(void);
00228 void d7a_alp_new_pkt(d7a_com_rx_msg_t* pkt);
00229 d7a_com_rx_msg_t* d7a_alp_wait_pkt(uint32_t millisec = osWaitForever);
00230 void d7a_alp_free_msg(d7a_msg_t* msg);
00231 d7a_msg_t** d7a_alp_write_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, const uint8_t* root_key, d7a_addressee_t* addressee = NULL, uint8_t retry = 0, bool resp = true);
00232 d7a_msg_t** d7a_alp_read_file(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* root_key, d7a_addressee_t* addressee = NULL, uint8_t retry = 0);
00233 d7a_msg_t** d7a_alp_flush_file(const uint8_t file_id, const uint8_t* root_key, d7a_addressee_t* addressee, uint8_t retry, bool resp);
00234 void d7a_alp_set_root_key_size(uint8_t size);
00235 
00236 
00237 #endif // _D7A_ALP_H_