WizziLab / modem_ref

Dependents:   modem_ref_helper

Revision:
56:67e3d9608403
Parent:
50:9eb5eed8b014
Child:
57:5444cfda9889
diff -r 7759000f5dee -r 67e3d9608403 include/modem_ref.h
--- a/include/modem_ref.h	Mon Jan 25 11:13:27 2021 +0100
+++ b/include/modem_ref.h	Wed Jan 27 14:45:28 2021 +0000
@@ -12,9 +12,10 @@
 ///             any architecture.
 //  =======================================================================
 
-#ifndef __MODEM_REF_DRV_H__
-#define __MODEM_REF_DRV_H__
+#ifndef __MODEM_REF_H__
+#define __MODEM_REF_H__
 
+#include "mbed.h"
 #include "hal_types.h"
 
 #include "alp_spec.h"
@@ -78,13 +79,13 @@
 TYPEDEF_STRUCT_PACKED
 {
     /// Automatic openning of D7A stack
-    u8  autostart_d7a;
+    uint8_t  autostart_d7a;
     /// Automatic 'Join' of LoRaWAN stack
-    u8  autostart_lwan;
+    uint8_t  autostart_lwan;
     /// Automatic procedure start time (sec)
-    u16 autostart_delay_s;
+    uint16_t autostart_delay_s;
     /// Debug COM port number (N/A:KAL_COM_NULL)
-    u8  dbg_com;
+    uint8_t  dbg_com;
 } wm_cfg_t;
 //}}}
 
@@ -92,17 +93,17 @@
 // before being sent to modem-driver through 'modem_input'.
 // An example deserializer can be found in "wc_deserialized.c".
 //======================================================================
-// modem_input
+// modem_ref_input
 //----------------------------------------------------------------------
 /// @brief  Parse packets and handles calls to relevant callbacks.
 /// @param  flowid      : WizziCom FlowID.
 /// @param  payload     : pointer to payload buffer.
 /// @param  size        : payload size in bytes.
 //======================================================================
-protected void modem_input(u8 flowid,u8* payload,u8 size);
+void modem_ref_input(uint8_t flowid, uint8_t* payload, uint8_t size);
 
 // Output:Modem-driver sends data to Modem through calls to the 'send'
-// function passed in 'modem_open'.
+// function passed in 'modem_ref_open'.
 // 'send' must be provided by the host application.
 //======================================================================
 // fx_serial_send_t
@@ -117,7 +118,7 @@
 /// @note                 buffer1 is used for WC header
 /// @note                 buffer2 is used actual payload
 //======================================================================
-typedef int  (fx_serial_send_t)     (u8* buffer1, u8 size1,u8* buffer2, u8 size2);
+typedef int  (fx_serial_send_t)     (uint8_t* buffer1, uint8_t size1, uint8_t* buffer2, uint8_t size2);
 
 //======================Low-Level-API================================}}}
 
@@ -136,7 +137,7 @@
 /// @param  length      : Access Size in bytes
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (fx_read_t)            (u8 fid,u32 offset,u32 length, int id);
+typedef void (fx_read_t)            (uint8_t fid, uint32_t offset, uint32_t length, int id);
 
 //======================================================================
 // fx_write_t
@@ -150,7 +151,7 @@
 /// @param  length      : Access Size in bytes
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (fx_write_t)           (u8 fid,void *data,u32 offset,u32 length, int id);
+typedef void (fx_write_t)           (uint8_t fid, void* data, uint32_t offset, uint32_t length, int id);
 
 //======================================================================
 // fx_read_fprop_t
@@ -161,7 +162,7 @@
 /// @param  fid         : File ID
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (fx_read_fprop_t)      (u8 fid, int id);
+typedef void (fx_read_fprop_t)      (uint8_t fid, int id);
 
 //======================================================================
 // fx_flush_t
@@ -172,7 +173,7 @@
 /// @param  fid         : File ID
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (fx_flush_t)           (u8 fid, int id);
+typedef void (fx_flush_t)           (uint8_t fid, int id);
 
 //======================================================================
 // fx_delete_t
@@ -183,7 +184,7 @@
 /// @param  fid         : File ID
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (fx_delete_t)          (u8 fid, int id);
+typedef void (fx_delete_t)          (uint8_t fid, int id);
 
 //======================================================================
 // fx_udata_t
@@ -193,36 +194,36 @@
 /// @param  data        : Pointer to the data buffer
 /// @param  length      : Data Size in bytes
 //======================================================================
-typedef void (fx_udata_t)           (void *data, u32 length);
+typedef void (fx_udata_t)           (void* data, uint32_t length);
 
 //======================================================================
 // fx_lqual_t
 //----------------------------------------------------------------------
 /// @brief  Called when LQUAL URC is generated by the modem.
-///         LQUAL URC is setup by the user through 'modem_enable_urc'.
+///         LQUAL URC is setup by the user through 'modem_ref_enable_urc'.
 ///         LQUAL gives percentage of successfully sent packets on a
 ///         particular interface (IFID).
 /// @param  ifid        : Interface File ID from which LQUAL is issued
 /// @param  per         : Packet Error Rate in %
 //======================================================================
-typedef void (fx_lqual_t)           (u8 ifid, int per);
+typedef void (fx_lqual_t)           (uint8_t ifid, int per);
 
 //======================================================================
 // fx_ldown_t
 //----------------------------------------------------------------------
 /// @brief  Called when LDOWN URC is generated by the modem.
-///         LDOWN URC is setup by the user through 'modem_enable_urc'
+///         LDOWN URC is setup by the user through 'modem_ref_enable_urc'
 ///         LDOWN is generated for a particular interface (IFID) after
 ///         a (configurable) number of consecutive transmission have failed.
 /// @param  ifid        : Interface File ID from which LDOWN is issued
 //======================================================================
-typedef void (fx_ldown_t)           (u8 ifid);
+typedef void (fx_ldown_t)           (uint8_t ifid);
 
 //======================================================================
 // fx_reset_t
 //----------------------------------------------------------------------
 /// @brief  Called when RESET URC is generated by the modem.
-///         LDOWN URC is setup by the user through 'modem_enable_urc'
+///         LDOWN URC is setup by the user through 'modem_ref_enable_urc'
 /// @param  ifid        : Interface File ID from which LDOWN is issued
 //======================================================================
 typedef void (fx_reset_t)           (void);
@@ -238,7 +239,7 @@
 ///                                         'W':Watchdog reset
 /// @param  nb_boot     : Number of boots since last POR
 //======================================================================
-typedef void (fx_boot_t)            (u8 cause, u16 nb_boot);
+typedef void (fx_boot_t)            (uint8_t cause, uint16_t nb_boot);
 
 //======================================================================
 // fx_busy_t
@@ -246,7 +247,7 @@
 /// @brief  Called when BUSY URC is generated by the modem.
 /// @param  busy       : 0 if not busy, else busy
 //======================================================================
-typedef void (fx_busy_t)            (u8 busy);
+typedef void (fx_busy_t)            (uint8_t busy);
 
 //======================================================================
 // fx_itf_busy_t
@@ -255,7 +256,7 @@
 /// @param  ifid       : interface file id
 /// @param  busy       : busy time in seconds
 //======================================================================
-typedef void (fx_itf_busy_t)        (u8 ifid, u32 busy);
+typedef void (fx_itf_busy_t)        (uint8_t ifid, uint32_t busy);
 
 // Set of functions passed together at modem openning
 typedef struct {
@@ -273,7 +274,21 @@
     fx_boot_t*          boot;
     fx_busy_t*          busy;
     fx_itf_busy_t*      itf_busy;
-} modem_callbacks_t;
+} modem_ref_callbacks_t;
+
+
+// LWAN
+typedef void (fx_packet_sent_t)         (void);
+typedef void (fx_lwan_itf_busy_t)       (uint32_t busy_time);
+typedef void (fx_join_failed_t)         (void);
+
+typedef struct {
+    fx_packet_sent_t*       packet_sent;
+    fx_lwan_itf_busy_t*     itf_busy;
+    fx_join_failed_t*       join_failed;
+} modem_lwan_callbacks_t;
+
+
 //======================High-Level-API===============================}}}
 
 //======================================================================
@@ -287,10 +302,10 @@
 /// @param  err         : ALP Error code
 /// @param  id          : ID of the request
 //======================================================================
-typedef void (action_callback_t)  (u8 terminal, s8 err, u8 id);
+typedef void (action_callback_t)  (uint8_t terminal, int8_t err, uint8_t id);
 
 //======================================================================
-// modem_open
+// modem_ref_open
 //----------------------------------------------------------------------
 /// @brief  Open Wizzilab Modem Driver
 /// @param  send        : User function implementing serial output.
@@ -298,213 +313,56 @@
 ///                       reception of commands
 /// @return 0
 //======================================================================
-public void modem_open(fx_serial_send_t* send,modem_callbacks_t* callbacks);
-public void modem_close(void);
+void modem_ref_open(fx_serial_send_t* send,modem_ref_callbacks_t* callbacks);
+void modem_ref_close(void);
+void modem_ref_set_lwan_cb(modem_lwan_callbacks_t* callbacks);
 
 //======================================================================
-// modem_get_id
+// modem_ref_get_id
 //----------------------------------------------------------------------
 /// @brief  Request an ID to perform modem operations
 /// @param  cb          : Function called on responses generated for
 ///                       this ID.
 /// @return Positive ID value, -1 if no more IDs available.
 //======================================================================
-public int modem_get_id(action_callback_t* cb);
+int modem_ref_get_id(action_callback_t* cb);
 
 //======================================================================
-// modem_free_id
+// modem_ref_free_id
 //----------------------------------------------------------------------
 /// @brief  Release an ID
 /// @param  id          : ID to release.
 /// @return ID value, -1 if ID was not in use.
 //======================================================================
-public int modem_free_id(u8 id);
+int modem_ref_free_id(uint8_t id);
 
 //======================================================================
 // "Action" functions performing requests to the modem
 //==================================================================={{{
 
-//======================================================================
-// modem_read_file
-//----------------------------------------------------------------------
-/// @brief  Read a file on Modem
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the destination data buffer
-/// @param  offset      : Access Offset in bytes
-/// @param  length      : Access Size in bytes
-/// @param  id          : User ID
-//======================================================================
-public void modem_read_file(u8 fid, void *data, u32 offset, u32 length, u8 id);
-
-//======================================================================
-// modem_read_fprop
-//----------------------------------------------------------------------
-/// @brief  Read a file-properties on Modem
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the destination data buffer
-/// @param  id          : User ID
-//======================================================================
-public void modem_read_fprop(u8 fid, alp_file_header_t* data, u8 id);
-
-//======================================================================
-// modem_read_fprop
-//----------------------------------------------------------------------
-/// @brief  Read a file-properties on Modem with ROOT privileges
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the destination data buffer
-/// @param  root_key    : Pointer to the ROOT key
-/// @param  id          : User ID
-//======================================================================
-public void modem_read_fprop_root(u8 fid, alp_file_header_t* data, u8* root_key, u8 id);
+void modem_ref_raw_alp(alp_pub_payload_t* alp, uint8_t id);
+void modem_ref_remote_raw_alp(void* itf, void* istatus, alp_pub_payload_t* alp, uint8_t id);
 
-//======================================================================
-// modem_write_fprop
-//----------------------------------------------------------------------
-/// @brief  Write a file-properties on Modem
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the header data
-/// @param  id          : User ID
-//======================================================================
-public void modem_write_fprop(u8 fid, alp_file_header_t* data, u8 id);
-
-//======================================================================
-// modem_write_fprop_root
-//----------------------------------------------------------------------
-/// @brief  Write a file-properties on Modem with ROOT privileges
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the header data
-/// @param  root_key    : Pointer to the ROOT key
-/// @param  id          : User ID
-//======================================================================
-public void modem_write_fprop_root(u8 fid, alp_file_header_t* data, u8* root_key, u8 id);
-
-//======================================================================
-// modem_write_file
-//----------------------------------------------------------------------
-/// @brief  Write a file on Modem
-/// @note   Writing can trigger a 'notification' depending on file properties.
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the source data buffer
-/// @param  offset      : Access Offset in bytes
-/// @param  length      : Access Size in bytes
-/// @param  id          : User ID
-//======================================================================
-public void modem_write_file(u8 fid, void *data, u32 offset, u32 length, u8 id);
-
-//======================================================================
-// modem_write_file_root
-//----------------------------------------------------------------------
-/// @brief  Write a file on Modem with ROOT privileges
-/// @note   Writing can trigger a 'notification' depending on file properties.
-/// @param  fid         : File ID
-/// @param  data        : Pointer to the source data buffer
-/// @param  offset      : Access Offset in bytes
-/// @param  length      : Access Size in bytes
-/// @param  root_key    : Pointer to the ROOT key
-/// @param  id          : User ID
-//======================================================================
-public void modem_write_file_root(u8 fid, void *data, u32 offset, u32 length, u8* root_key, u8 id);
+void modem_ref_read_file(uint8_t fid, void* data, uint32_t offset, uint32_t length, uint8_t id);
+void modem_ref_remote_read_file(void* itf, void* istatus, uint8_t fid, void* data, uint32_t offset, uint32_t length, uint8_t id);
 
-//======================================================================
-// modem_flush_file
-//----------------------------------------------------------------------
-/// @brief  Flush a file on Modem
-/// @param  fid         : File ID
-/// @param  id          : User ID
-//======================================================================
-public void modem_flush_file(u8 fid, u8 id);
-
-//======================================================================
-// modem_write_file_root
-//----------------------------------------------------------------------
-/// @brief  Flush a file on Modem with ROOT privileges
-/// @param  fid         : File ID
-/// @param  root_key    : Pointer to the ROOT key
-/// @param  id          : User ID
-//======================================================================
-public void modem_flush_file_root(u8 fid, u8* root_key, u8 id);
-
-//======================================================================
-// modem_declare_file
-//----------------------------------------------------------------------
-/// @brief  Declare a local file to the Modem. Once declared, the file
-///         becomes virtually part of Modem's file-system and can:
-///         - be remotely accessed (depending on its permissions)
-///         - be "Notified" through notify_file use
-/// @note   The file must exist locally.
-/// @note   Modem will access the file when needed using ALP commands.
-/// @param  fid         : File ID
-/// @param  hdr         : ALP File Header.
-/// @param  local       : File is local.
-/// @param  id          : User ID
-//======================================================================
-public void modem_declare_file(u8 fid, alp_file_header_t* hdr, u8 local, u8 id);
-
-//======================================================================
-// modem_create_file
-//----------------------------------------------------------------------
-/// @brief  Creates a file on the Modem.
-/// @param  fid         : File ID
-/// @param  hdr         : ALP File Header.
-/// @param  id          : User ID
-//======================================================================
-public void modem_create_file(u8 fid, alp_file_header_t* hdr, u8 id);
+void modem_ref_write_file(uint8_t fid, void* data, uint32_t offset, uint32_t length, uint8_t id);
+void modem_ref_remote_write_file(void* itf, void* istatus, uint8_t fid, void* data, uint32_t offset, uint32_t length, uint8_t id);
 
-//======================================================================
-// modem_delete_file
-//----------------------------------------------------------------------
-/// @brief  Deletes a file on the Modem.
-/// @param  fid         : File ID
-/// @param  id          : User ID
-//======================================================================
-public void modem_delete_file(u8 fid, u8 id);
-
-public void modem_delete_file_root(u8 fid, u8* root_key, u8 id);
-
-//======================================================================
-// modem_notify_file
-//----------------------------------------------------------------------
-/// @brief  "Notify" a local file using its D7AActP properties.
-/// @note   The file must exist locally and must have been 'declared'.
-/// @param  fid         : File ID
-/// @param  offset      : Access Offset in bytes
-/// @param  length      : Access Size in bytes
-/// @param  id          : User ID
-//======================================================================
-public void modem_notify_file(u8 fid, u32 offset, u32 length, u8 id);
+void modem_ref_flush_file(uint8_t fid, uint8_t id);
+void modem_ref_declare_file(u8 fid, alp_file_header_t* hdr, int id);
 
-//======================================================================
-// modem_alp_raw
-//----------------------------------------------------------------------
-/// @brief  Execute specific ALP payload on Modem.
-/// @param  payload     : pointer to ALP Payload to be executed on Modem
-/// @param  length      : ALP Payload size
-/// @param  id          : User ID
-//======================================================================
-public void modem_send_raw_alp(u8* payload, u32 length, u8 id);
-
-public void modem_send_file_content(u8* itf, u8 itf_length, void *istatus, u8 fid, void *data,u32 offset,u32 length, u8 id);
-
-public void modem_remote_read_file(u8* itf, u8 itf_length, void *istatus , u8 fid, void *data, u32 offset, u32 length, u8 id);
-
-public void modem_remote_read_file_root(u8* itf, u8 itf_length, void *istatus , u8 fid, void *data, u32 offset, u32 length, u8* root_key, u8 id);
-
-public void modem_remote_write_file(u8* itf, u8 itf_length, void *istatus , u8 fid, void *data, u32 offset, u32 length, u8 id);
-
-public void modem_remote_write_file_root(u8* itf, u8 itf_length, void *istatus , u8 fid, void *data, u32 offset, u32 length, u8* root_key, u8 id);
-
-public void modem_enable_urc(u8 type, u8 ifid, u8 val, u8 enable, u8 id);
-
-public void modem_activate_itf(u8 type, u8 nb_dev, u8 ifid, u8 flags, u8 enable, u8 id);
+void modem_ref_activate_itf(uint8_t type, uint8_t nb_dev, uint8_t ifid, uint8_t flags, uint8_t enable, uint8_t id);
+void modem_ref_enable_urc(uint8_t type, uint8_t ifid, uint8_t val, uint8_t id);
 
 //==========================Action===================================}}}
 
 //======================================================================
 // "Response" functions to be called-back on requests from the modem
 //==================================================================={{{
-public void modem_respond(s8 status, int id);
-public void modem_respond_fprop(u8 fid, u8* hdr, int id);
-public void modem_respond_read(u8 fid,void *data,u32 offset,u32 length, int id);
+void modem_ref_respond(int8_t status, int id);
+void modem_ref_respond_fprop(uint8_t fid, alp_file_header_t* hdr, int id);
+void modem_ref_respond_read(uint8_t fid, void* data, uint32_t offset, uint32_t length, int id);
 //==========================Response=================================}}}
 
 
@@ -515,66 +373,77 @@
 // applications.
 //=======================================================================
 // Modem Config/Status
-#define FID_WM_REV                        2 // Match D7A one.
-#define FID_HOST_REV                     65
-#define FID_WM_SCRATCH                   66
-#define FID_WM_STATUS                    67
-#define FID_WM_CFG                       68
-#define FID_WM_HWCFG                     69
-#define FID_WM_CTRL                      70
-#define FID_WM_LED_CFG                   71
-#define FID_WM_DEBUG                     72
-#define FID_WM_POWER_STATUS              73 // For GW power supervisor reporting
+#define FID_WM_REV                      2 // aka D7A_FID_FIRMWARE_VERSION
+#define FID_WM_RFU_64                  64
+#define FID_HOST_REV                   65
+#define FID_WM_SCRATCH                 66
+#define FID_WM_STATUS                  67
+#define FID_WM_CFG                     68
+#define FID_WM_HWCFG                   69
+#define FID_WM_CTRL                    70
+#define FID_WM_LED_CFG                 71
+#define FID_WM_DEBUG                   72
+#define FID_WM_POWER_STATUS            73 // For GW power supervisor reporting
+#define FID_WM_TLEV                    74 // Trace levels
+#define FID_WM_USER_STORAGE            75 // Big generic file for APPs to store data since we can't create permanent files on NRF52.
+#define FID_WM_INVT                    76 // Inventory commands
+#define FID_WM_RFU_77                  77
+#define FID_WM_RFU_78                  78
+#define FID_WM_RFU_79                  79
 
-// LORAWAN "ITFs"
-#define FID_LWAN_ITF0                    98
-#define FID_LWAN_ITF1                    99
+// LORAWAN Stack
+#define FID_LWAN_CFG                   96
+#define FID_LWAN_NLS                   97
+#define FID_LWAN_ITF                   98 // XXX useless
+#define FID_LWAN_STATUS                99
 
 // Action files
-#define FID_ACTP_RPT_FULL               100
-#define FID_ACTP_RPT_PART               101
+#define FID_ACTP_RPT_FULL             100
+#define FID_ACTP_RPT_PART             101
 
-// Reserved 
-#define FID_RESERVED_102                102
-#define FID_RESERVED_103                103
-#define FID_RESERVED_104                104
-#define FID_RESERVED_105                105
-#define FID_RESERVED_106                106
-#define FID_RESERVED_107                107
+// Unallocated FIDs
+#define FID_UNUSED_102                102
+#define FID_UNUSED_103                103
+#define FID_UNUSED_104                104
+#define FID_UNUSED_105                105
+#define FID_UNUSED_106                106
+#define FID_UNUSED_107                107
+#define FID_UNUSED_108                108
+#define FID_UNUSED_109                109
+
+#define IFID_REPORT                   110
 
-// Interface files
-#define IFID_ONESHOT_HOST               108
-#define IFID_ONESHOT_ACTP               109
-#define IFID_REPORT                     110
-#define IFID_ITF3                       111
-#define IFID_ITF4                       112
-#define IFID_BLINKER                    113
-
-// Reserved 
-#define FID_RESERVED_114                114 
-#define FID_RESERVED_115                115 
-#define FID_RESERVED_116                116 
-#define FID_RESERVED_117                117 
-#define FID_RESERVED_118                118 
-#define FID_RESERVED_119                119 
-#define FID_RESERVED_120                120 
-#define FID_RESERVED_121                121 
-#define FID_RESERVED_122                122 
-#define FID_RESERVED_123                123 
+// Unallocated FIDs
+#define FID_UNUSED_111                111
+#define FID_UNUSED_112                112
+#define FID_UNUSED_113                113
+#define FID_UNUSED_114                114
+#define FID_UNUSED_115                115
+#define FID_UNUSED_116                116
+#define FID_UNUSED_117                117
+#define FID_UNUSED_118                118
+#define FID_UNUSED_119                119
+#define FID_UNUSED_120                120
+#define FID_UNUSED_121                121
+#define FID_UNUSED_122                122
+#define FID_UNUSED_123                123
 
 // Modem Security protocols
-#define FID_WM_CHALLENGE                124
+#define FID_WM_CHALLENGE              124
 
 // Modem CUP
-#define FID_CUP_CFG_BCAST               125
-#define FID_CUP_CFG                     126
-#define FID_CUP_CODE                    127
+#define FID_CUP_CFG_BCAST             125
+#define FID_CUP_CFG                   126
+#define FID_CUP_CODE                  127
 
 // HST CUP
-#define FID_APP_CUP_CFG_BCAST           252
-#define FID_APP_CUP_CFG                 253
-#define FID_APP_CUP_CODE                254
+#define FID_APP_CUP_CFG_BCAST         252
+#define FID_APP_CUP_CFG               253
+#define FID_APP_CUP_CODE              254
+
+// System status
+#define FID_SYS_STATUS                255
 
 #endif
 
-// vim:fdm=marker:fdc=2
+// vim:fdm=marker:fdc=2
\ No newline at end of file