Exportable version of WizziLab's modem driver.

Dependents:   modem_ref_helper

Revision:
56:67e3d9608403
Parent:
47:cf4519ba56d9
Child:
60:08efaaca0e83
--- a/include/alp_spec.h	Mon Jan 25 11:13:27 2021 +0100
+++ b/include/alp_spec.h	Wed Jan 27 14:45:28 2021 +0000
@@ -1,40 +1,8 @@
 /// @copyright
 /// ========================================================================={{{
-/// Copyright (c) 2012-2018 WizziLab                                           /
+/// Copyright (c) 2012-2020 WizziLab                                           /
 /// All rights reserved                                                        /
 ///                                                                            /
-/// IMPORTANT: This Software may not be modified, copied or distributed unless /
-/// embedded on a WizziLab product. Other than for the foregoing purpose, this /
-/// Software and/or its documentation may not be used, reproduced, copied,     /
-/// prepared derivative works of, modified, performed, distributed, displayed  /
-/// or sold for any purpose. For the sole purpose of embedding this Software   /
-/// on a WizziLab product, copy, modification and distribution of this         /
-/// Software is granted provided that the following conditions are respected:  /
-///                                                                            /
-/// *  Redistributions of source code must retain the above copyright notice,  /
-///    this list of conditions and the following disclaimer                    /
-///                                                                            /
-/// *  Redistributions in binary form must reproduce the above copyright       /
-///    notice, this list of conditions and the following disclaimer in the     /
-///    documentation and/or other materials provided with the distribution.    /
-///                                                                            /
-/// *  The name of WizziLab can not be used to endorse or promote products     /
-///    derived from this software without specific prior written permission.   /
-///                                                                            /
-/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        /
-/// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED  /
-/// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR /
-/// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR          /
-/// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,      /
-/// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,        /
-/// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,            /
-/// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     /
-/// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    /
-/// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         /
-/// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               /
-/// WIZZILAB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,       /
-/// ENHANCEMENTS OR MODIFICATIONS.                                             /
-///                                                                            /
 /// Should you have any questions regarding your right to use this Software,   /
 /// contact WizziLab at www.wizzilab.com.                                      /
 ///                                                                            /
@@ -98,6 +66,7 @@
     ALP_OPCODE_RSP_EOPTAG               = ALP_OPCODE_RSP_TAG + ALP_OPCODE_EOP, //|   PID
     ALP_OPCODE_RSP_ERRTAG               = ALP_OPCODE_RSP_TAG + ALP_OPCODE_ERR, //|   PID
     ALP_OPCODE_RSP_URC                  = 36, //|
+    ALP_OPCODE_RSP_SECURED              = 37, //|
 
     ALP_OPCODE_CHUNK                    = 48, //|  -
     ALP_OPCODE_LOGIC                    = 49, //|  -
@@ -167,6 +136,7 @@
     ALP_ERR_FS_TIMEOUT,                       // 0x81: Internal FS Error
     ALP_ERR_ITF_UNKNOWN,                      // 0x82: Unknown Interface
     ALP_ERR_ITF_TIMEOUT,                      // 0x83: Internal ITF Error
+    ALP_ERR_CHAL_NOT_VALID                    // 0x84: Challenge has expired
 
 } alp_errors_t;
 
@@ -215,7 +185,7 @@
     ALP_URC_TYPE_LQUAL                  = 0,
     /// Enable Link Down (on IFID) URCs on requesting ITF
     ALP_URC_TYPE_LDOWN                  = 1,
-    /// Enable system/modem URC 
+    /// Enable system/modem URC
     /// XXX Could enable subtypes, but API does not allow it
     ALP_URC_TYPE_BUSY                   = 2,
     /// Enable Interface BUSY messages
@@ -269,8 +239,8 @@
 
 #define ALP_ACTION_F_RD_DATA_SIZE(_o,_l)        (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l))
 #define ALP_ACTION_F_RD_DATA_SIZE_MAX           (2+4+4)
-#define ALP_ACTION_F_RD_DATA(_p,_r,_fid,_o,_l) do {\
-    *(_p)++ = (_r)?ALP_OPCODE_F_RD_DATA+ALP_OPCODE_RESP:ALP_OPCODE_F_RD_DATA;\
+#define ALP_ACTION_F_RD_DATA(_p,_r,_fid,_o,_l,_g) do {\
+    *(_p)++ = ALP_OPCODE_F_RD_DATA | ((_r)? ALP_OPCODE_RESP: 0) | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = (_fid);\
     (_p) += alp_encode_length(_p,_o);\
     (_p) += alp_encode_length(_p,_l);\
@@ -284,8 +254,8 @@
 
 #define ALP_ACTION_F_WR_DATA_SIZE(_o,_l)        (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l)+(_l))
 #define ALP_ACTION_F_WR_DATA_SIZE_MAX(_l)       (2+4+4+(_l))
-#define ALP_ACTION_F_WR_DATA(_p,_r,_fid,_o,_l,_data) do {\
-    *(_p)++ = (_r)?ALP_OPCODE_F_WR_DATA+ALP_OPCODE_RESP:ALP_OPCODE_F_WR_DATA;\
+#define ALP_ACTION_F_WR_DATA(_p,_r,_fid,_o,_l,_data,_g) do {\
+    *(_p)++ = ALP_OPCODE_F_WR_DATA | ((_r)? ALP_OPCODE_RESP: 0) | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = (_fid);\
     (_p) += alp_encode_length(_p,_o);\
     (_p) += alp_encode_length(_p,_l);\
@@ -333,8 +303,8 @@
     } while(0)
 
 #define ALP_ACTION_F_FLUSH_SIZE                 (2)
-#define ALP_ACTION_F_FLUSH(_p,_r,_fid)   do {\
-    *(_p)++ = (_r)?ALP_OPCODE_F_FLUSH+ALP_OPCODE_RESP:ALP_OPCODE_F_FLUSH;\
+#define ALP_ACTION_F_FLUSH(_p,_r,_fid,_g)   do {\
+    *(_p)++ = ALP_OPCODE_F_FLUSH | ((_r)? ALP_OPCODE_RESP: 0) | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = (_fid);\
     } while(0)
 
@@ -347,21 +317,37 @@
 
 #define ALP_PERM_REQ_USER                       0
 #define ALP_PERM_REQ_ROOT                       1
+#define ALP_PERM_REQ_APP                        2
 
-// Wizzilab's specific Authentication-Protocol-Id
+// Authentication Protocol without initialization data
 #define ALP_WIZZILAB_AUTH_PROTOCOL_ID           42
-#define ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE   8
-#define ALP_ACTION_PERM_REQ_OFFSET              (3+ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE)
+// Challenge Encryption-Authentication Protocol
+#define ALP_WIZZILAB_CHAL_PROTOCOL_ID           43
+// Authentication Protocol with initialization data
+#define ALP_WIZZILAB_SIGN_PROTOCOL_ID           44
+
+#define ALP_ACTION_PERM_REQ_TOKEN_SIZE          8
+#define ALP_ACTION_PERM_REQ_OFFSET              (3+ALP_ACTION_PERM_REQ_TOKEN_SIZE)
 #define ALP_ACTION_PERM_REQ_SIZE(_l)            (ALP_ACTION_PERM_REQ_OFFSET+(_l))
-#define ALP_ACTION_PERM_REQ(_p,_r,_role)   do {\
+#define ALP_ACTION_PERM_REQ(_p,_r,_role, _protocol)   do {\
     *(_p)++ = (_r)?ALP_OPCODE_PERM_REQ+ALP_OPCODE_RESP:ALP_OPCODE_PERM_REQ;\
     *(_p)++ = (_role);\
-    *(_p)++ = ALP_WIZZILAB_AUTH_PROTOCOL_ID;\
+    *(_p)++ = (_protocol);\
     } while(0)
 
-// Wizzilab's specific Challenge-Encryption-Authentication-Protocol-Id
-#define ALP_WIZZILAB_CHAL_PROTOCOL_ID           43
-#define ALP_WIZZILAB_CHAL_PROTOCOL_TOKEN_SIZE   ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE
+#define ALP_SECURED_USER                        ALP_PERM_REQ_USER
+#define ALP_SECURED_ROOT                        ALP_PERM_REQ_ROOT
+#define ALP_SECURED_APP                         ALP_PERM_REQ_APP
+
+#define ALP_ACTION_SECURED_IV_SIZE              8
+#define ALP_ACTION_SECURED_TOKEN_SIZE           8
+#define ALP_ACTION_SECURED_OFFSET               (3+ALP_ACTION_SECURED_IV_SIZE+ALP_ACTION_SECURED_TOKEN_SIZE)
+#define ALP_ACTION_SECURED_SIZE(_l)             (ALP_ACTION_SECURED_OFFSET+(_l))
+#define ALP_ACTION_SECURED(_p,_role, _protocol)   do {\
+    *(_p)++ = ALP_OPCODE_RSP_SECURED;\
+    *(_p)++ = (_role);\
+    *(_p)++ = (_protocol);\
+    } while(0)
 
 #define ALP_ACTION_URCC_SIZE(t)                 ((t==ALP_URC_TYPE_NONE)?2:4)
 #define ALP_ACTION_URCC_EN(_p,_r,_type,_ifid,_cfg)  do {\
@@ -425,8 +411,8 @@
 #define ALP_ACTION_RSP_TAG_SIZE                     (2)
 #define ALP_ACTION_RSP_TAG(_p,_val,_eop,_err)  do {\
     u8 tmp = ALP_OPCODE_RSP_TAG;\
-    tmp |= (_eop)?ALP_OPCODE_EOP:0;\
-    tmp |= (_err)?ALP_OPCODE_ERR:0;\
+    tmp |= (_eop)? ALP_OPCODE_EOP: 0;\
+    tmp |= (_err)? ALP_OPCODE_ERR: 0;\
     *(_p)++ = tmp;\
     *(_p)++ = (_val);\
     } while(0)
@@ -471,19 +457,32 @@
 // Simple Query actions
 /// Match immediate value to file value
 #define ALP_ACTION_QUERY_EQVAL_SIZE(_o,_l,_mbit)    (4+ALP_LFIELD_SIZE(_o)+(1+(_mbit))*(_l))
-#define ALP_ACTION_QUERY_EQVAL(_p,_m,_v,_fid,_o,_l)   do {\
+#define ALP_ACTION_QUERY_EQVAL(_p,_m,_v,_fid,_o,_l,_g)   do {\
     u8 _mbit = (_m) ? 1 : 0;\
-    *(_p)++ = ALP_OPCODE_QUERY;\
+    *(_p)++ = ALP_OPCODE_QUERY | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = ALP_QCOMP(ALP_QCOMP_EQ) | ALP_QDATA(ALP_QDATA_UNSIGNED) | ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_ACOMP_IMMEDIATE);\
     *(_p)++ = _l;\
     if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
     memcpy((_p),&(_v),_l);(_p) += (_l);\
-    *(_p)++ = _fid;\
-    (_p) += alp_encode_length(_p,_o);\
+    *(_p)++ = (_fid);\
+    (_p) += alp_encode_length((_p),(_o));\
+    } while(0)
+
+#define ALP_ACTION_QUERY_SIZE(_o,_l,_mbit)    (4+ALP_LFIELD_SIZE(_o)+(1+(_mbit))*(_l))
+
+/// Match array XXX pass data pointer
+#define ALP_ACTION_QUERY_STRTOK(_p,_m,_d,_fid,_o,_l,_g)   do {\
+    u8 _mbit = (_m) ? 1 : 0;\
+    *(_p)++ = ALP_OPCODE_QUERY | ((_g)? ALP_OPCODE_GROUP: 0);\
+    *(_p)++ = ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_STR_TOKEN) | ALP_QSTR_PARAM(0);\
+    *(_p)++ = (_l);\
+    if (_mbit) {memcpy((_p),&(_m),(_l)); (_p) += (_l);}\
+    memcpy((_p),(_d),(_l)); (_p) += (_l);\
+    *(_p)++ = (_fid);\
+    (_p) += alp_encode_length((_p),(_o));\
     } while(0)
 
 // Query with break actions
-/// Match immediate value to file value
 #define ALP_ACTION_QBREAK_SIZE(_o,_l,_mbit)    (4+ALP_LFIELD_SIZE(_o)+(1+(_mbit))*(_l))
 
 /// Compare immediate value to file value
@@ -491,22 +490,23 @@
     u8 _mbit = (_m) ? 1 : 0;\
     *(_p)++ = ALP_OPCODE_QBREAK | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = ALP_QCOMP(_c) | ALP_QDATA(ALP_QDATA_UNSIGNED) | ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_ACOMP_IMMEDIATE);\
-    *(_p)++ = _l;\
-    if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
-    memcpy((_p),&(_v),_l);(_p) += (_l);\
+    *(_p)++ = (_l);\
+    if (_mbit) {memcpy((_p),&(_m),(_l));(_p) += (_l);}\
+    memcpy((_p),&(_v),(_l));(_p) += (_l);\
     *(_p)++ = _fid;\
-    (_p) += alp_encode_length(_p,_o);\
+    (_p) += alp_encode_length((_p),(_o));\
     } while(0)
 
-#define ALP_ACTION_QBREAK_STRTOK(_p,_m,_v,_fid,_o,_l,_g)   do {\
+/// Match array XXX pass data pointer
+#define ALP_ACTION_QBREAK_STRTOK(_p,_m,_d,_fid,_o,_l,_g)   do {\
     u8 _mbit = (_m) ? 1 : 0;\
     *(_p)++ = ALP_OPCODE_QBREAK | ((_g)? ALP_OPCODE_GROUP: 0);\
     *(_p)++ = ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_STR_TOKEN) | ALP_QSTR_PARAM(0);\
-    *(_p)++ = _l;\
-    if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
-    memcpy((_p),&(_v),_l);(_p) += (_l);\
-    *(_p)++ = _fid;\
-    (_p) += alp_encode_length(_p,_o);\
+    *(_p)++ = (_l);\
+    if (_mbit) {memcpy((_p),&(_m),(_l)); (_p) += (_l);}\
+    memcpy((_p),(_d),(_l)); (_p) += (_l);\
+    *(_p)++ = (_fid);\
+    (_p) += alp_encode_length((_p),(_o));\
     } while(0)
 
 #define ALP_ACTION_QLOGIC_SIZE   1