WizziLab / modem_ref_v5_3_217

Dependents:   modem_ref_helper_for_v5_3_217

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers alp_spec.h Source File

alp_spec.h

Go to the documentation of this file.
00001 /// @copyright
00002 /// ========================================================================={{{
00003 /// Copyright (c) 2012-2018 WizziLab                                           /
00004 /// All rights reserved                                                        /
00005 ///                                                                            /
00006 /// IMPORTANT: This Software may not be modified, copied or distributed unless /
00007 /// embedded on a WizziLab product. Other than for the foregoing purpose, this /
00008 /// Software and/or its documentation may not be used, reproduced, copied,     /
00009 /// prepared derivative works of, modified, performed, distributed, displayed  /
00010 /// or sold for any purpose. For the sole purpose of embedding this Software   /
00011 /// on a WizziLab product, copy, modification and distribution of this         /
00012 /// Software is granted provided that the following conditions are respected:  /
00013 ///                                                                            /
00014 /// *  Redistributions of source code must retain the above copyright notice,  /
00015 ///    this list of conditions and the following disclaimer                    /
00016 ///                                                                            /
00017 /// *  Redistributions in binary form must reproduce the above copyright       /
00018 ///    notice, this list of conditions and the following disclaimer in the     /
00019 ///    documentation and/or other materials provided with the distribution.    /
00020 ///                                                                            /
00021 /// *  The name of WizziLab can not be used to endorse or promote products     /
00022 ///    derived from this software without specific prior written permission.   /
00023 ///                                                                            /
00024 /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        /
00025 /// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED  /
00026 /// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR /
00027 /// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR          /
00028 /// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,      /
00029 /// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,        /
00030 /// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,            /
00031 /// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     /
00032 /// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    /
00033 /// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         /
00034 /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               /
00035 /// WIZZILAB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,       /
00036 /// ENHANCEMENTS OR MODIFICATIONS.                                             /
00037 ///                                                                            /
00038 /// Should you have any questions regarding your right to use this Software,   /
00039 /// contact WizziLab at www.wizzilab.com.                                      /
00040 ///                                                                            /
00041 /// =========================================================================}}}
00042 /// @endcopyright
00043 
00044 //  =======================================================================
00045 /// @file           alp_spec.h
00046 /// @defgroup       ALP
00047 /// @brief          ALP definitions from D7A specification
00048 //  =======================================================================
00049 
00050 #ifndef __ALP_SPEC_H__
00051 #define __ALP_SPEC_H__
00052 
00053 #include "hal_types.h"
00054 
00055 // Opcode Modifiers / Preemption flags
00056 #define ALP_OPCODE_RESP                 0x40
00057 #define ALP_OPCODE_GROUP                0x80
00058 #define ALP_OPCODE_ERR                  0x40
00059 #define ALP_OPCODE_EOP                  0x80
00060 #define ALP_OPCODE_ITF                  0x40
00061 #define ALP_OPCODE_INDIRECT             0x40
00062 #define ALP_OPCODE_OVERLOAD             0x80
00063 
00064 typedef enum {
00065 //      OPCODE                                  | OPERAND
00066     ALP_OPCODE_NOP                      = 0,  //|   -
00067 
00068     ALP_OPCODE_F_RD_DATA                = 1,  //|  FDR
00069     ALP_OPCODE_F_RD_PROP                = 2,  //|  FID
00070 
00071     ALP_OPCODE_F_WR_DATA                = 4,  //|  FD
00072     ALP_OPCODE_F_WR_FLUSH               = 5,  //|  FD
00073     ALP_OPCODE_F_WR_PROP                = 6,  //|  FD
00074     ALP_OPCODE_F_TOUCH                  = 7,  //|  FD
00075 
00076     ALP_OPCODE_QUERY                    = 8,  //|   Q
00077     ALP_OPCODE_QBREAK                   = 9,  //|   Q
00078     ALP_OPCODE_PERM_REQ                 = 10, //|   P
00079 
00080     ALP_OPCODE_CRC_CHECK                = 11, //|  Q
00081 
00082     ALP_OPCODE_F_EXIST                  = 16, //|  FID
00083     ALP_OPCODE_F_CREATE                 = 17, //|  FD
00084     ALP_OPCODE_F_DELETE                 = 18, //|  FID
00085     ALP_OPCODE_F_RESTORE                = 19, //|  FID
00086     ALP_OPCODE_F_FLUSH                  = 20, //|  FID
00087     ALP_OPCODE_F_DECLARE                = 21, //|  FH XXX Deprecated DO NOT USE !!!
00088     ALP_OPCODE_F_CLOSE                  = 22, //|  FID
00089     ALP_OPCODE_F_COPY                   = 23, //|  2xFID
00090     ALP_OPCODE_F_EXECUTE                = 31, //|  FID
00091 
00092     ALP_OPCODE_RSP_F_DATA               = 32, //|  FD
00093     ALP_OPCODE_RSP_F_PROP               = 33, //|  FH
00094     ALP_OPCODE_RSP_STATUS               = 34, //|  S
00095     ALP_OPCODE_RSP_ISTATUS              = ALP_OPCODE_RSP_STATUS + ALP_OPCODE_ITF, //|   SI
00096     ALP_OPCODE_RSP_EOPISTATUS           = ALP_OPCODE_RSP_STATUS + ALP_OPCODE_ITF + ALP_OPCODE_EOP, //|   SI
00097     ALP_OPCODE_RSP_TAG                  = 35, //|  PID
00098     ALP_OPCODE_RSP_EOPTAG               = ALP_OPCODE_RSP_TAG + ALP_OPCODE_EOP, //|   PID
00099     ALP_OPCODE_RSP_ERRTAG               = ALP_OPCODE_RSP_TAG + ALP_OPCODE_ERR, //|   PID
00100     ALP_OPCODE_RSP_URC                  = 36, //|
00101 
00102     ALP_OPCODE_CHUNK                    = 48, //|  -
00103     ALP_OPCODE_LOGIC                    = 49, //|  -
00104     ALP_OPCODE_FORWARD                  = 50, //|  I
00105     ALP_OPCODE_IFORWARD                 = 51, //|  IFID
00106     ALP_OPCODE_TAG                      = 52, //|  PID
00107     ALP_OPCODE_URCC                     = 53, //|
00108 
00109     ALP_OPCODE_EXT                      = 63, //| OP |ARGC| ARGS       |
00110                                               //| 1B | 1B | ARGC-bytes |
00111 } alp_opcodes_t;
00112 #define ALP_OPCODE_UNKNOWN              (-1)
00113 
00114 typedef enum {
00115     ALP_ITF_TYPE_HOST                   = 0x00,
00116     ALP_ITF_TYPE_BLE                    = 0xB0,
00117     ALP_ITF_TYPE_COM                    = 0xC0,
00118     ALP_ITF_TYPE_D7A                    = 0xD7, // Only this one actually in D7A Spec
00119     ALP_ITF_TYPE_LWAN                   = 0x10,
00120 
00121     ALP_ITF_TYPE_NONE                   = 0xFF
00122 } alp_itf_type_t;
00123 
00124 // EXTOpcode Modifiers / Preemption flags
00125 #define ALP_EXTOPCODE_DISTANT           0x40 // Used w/ EXTOPCODE_F_DECLARE
00126 
00127 typedef enum {
00128 //  WIZZILAB OPCODE EXTENSION
00129     ALP_EXTOPCODE_ITF_START             = 0,  //|   'ITF' activation operations:
00130     ALP_EXTOPCODE_ITF_STOP              = 1,  //| TYPE | DEVQ | IFID | FLAGS |
00131     ALP_EXTOPCODE_ITF_PAUSE             = 2,  //|  1B  |  1B  |  1B  |  1B   |
00132                                              //| TYPE: ITF Type (D7A,LWAN,BLE...)
00133                                              //| DEVQ: ITF Max Device number if applicable
00134                                              //| IFID: ITF Config file if applicable
00135                                              //| FLAG: Additional configuration flags if applicable
00136     ALP_EXTOPCODE_F_DECLARE             = 21, //| FH
00137 } alp_ext_opcodes_t;
00138 
00139 typedef enum
00140 {
00141     ALP_ERR_ITF_FULL                    =  2, // 0x02: For interfaces supporting buffering, indicates buffer reached maximum capacity (no data loss)
00142     ALP_ERR_PARTIAL_COMPLETION          =  1, // 0x01: Action received and partially completed at response.  To be completed after response
00143 
00144     ALP_ERR_NONE                        =  0, // 0x00: Action completed (OK)
00145     ALP_ERR_FILE_NOT_FOUND              = -1, // 0xFF: Error access file: File ID does not exist
00146     ALP_ERR_FILE_EXIST                  = -2, // 0xFE: Error create file: File ID already exists
00147     ALP_ERR_FILE_NOT_RESTORABLE         = -3, // 0xFD: Error restore file: File is not restorable
00148     ALP_ERR_PERMISSION_DENIED           = -4, // 0xFC: Error access file: Insufficient permissions
00149     ALP_ERR_LENGTH_OVERFLOW             = -5, // 0xFB: Error create file: Supplied length (in header) is beyond file limits
00150     ALP_ERR_ALLOC_OVERFLOW              = -6, // 0xFA: Error create file: Supplied allocation (in header) is beyond file limits
00151     ALP_ERR_OFFSET_OVERFLOW             = -7, // 0xF9: Error write: Supplied start offset is out of bounds of file allocation
00152     ALP_ERR_WRITE_OVERFLOW              = -8, // 0xF8: Error complete write: Supplied data goes beyond file allocation
00153     ALP_ERR_WRITE_ERROR                 = -9, // 0xF7: Error write: impossible to write in storage location
00154     ALP_ERR_OPERATION_UNKNOWN           = -10,// 0xF6: Error unknown Operation
00155     ALP_ERR_OPERAND_INCOMPLETE          = -11,// 0xF5: Error incomplete Operand
00156     ALP_ERR_OPERAND_WRONG_FORMAT        = -12,// 0xF4: Error wrong Operand format
00157     ALP_ERR_ITF_INVALID                 = -13,// 0xF3: Error invalid interface
00158     ALP_ERR_ITF_OVERFLOW                = -14,// 0xF2: Error interface overflown (i.e. resources exhausted, buffer full with data discarded)
00159     ALP_ERR_QUERY_FAIL                  = -15,// 0xF1: (Group of) Query result was false (Informative error code).
00160     ALP_ERR_ITF_NOT_READY               = -16,// 0xF0: Error interface is not ready
00161 
00162     ALP_ERR_ITF_START                   = -64,// 0xC0: Interface specific error, start range
00163     ALP_ERR_ITF_END                     = -96,// 0xA0: Interface specific error, end range
00164     ALP_ERR_ITF_NOT_SPECIFIED           = ALP_ERR_ITF_END, // Not specified internal interface error.
00165 
00166     ALP_ERR_UNKNOWN                     = -128,// 0x80: Unknown error
00167     ALP_ERR_FS_TIMEOUT,                       // 0x81: Internal FS Error
00168     ALP_ERR_ITF_UNKNOWN,                      // 0x82: Unknown Interface
00169     ALP_ERR_ITF_TIMEOUT,                      // 0x83: Internal ITF Error
00170 
00171 } alp_errors_t;
00172 
00173 typedef enum {
00174     ALP_QCOMP_NE                        = 0,
00175     ALP_QCOMP_EQ                        = 1,
00176     ALP_QCOMP_LT                        = 2,
00177     ALP_QCOMP_LTE                       = 3,
00178     ALP_QCOMP_GT                        = 4,
00179     ALP_QCOMP_GTE                       = 5
00180 } alp_q_comp_t;
00181 #define ALP_QCOMP(v)                   (((v) & 7) << 0)
00182 #define ALP_QSTR_PARAM(v)              (((v) & 0x0F) << 0)
00183 
00184 typedef enum {
00185     // This is not matching ALP's spec on purpose...
00186     ALP_QLOGIC_AND                      = 0,
00187     ALP_QLOGIC_OR                       = 1,
00188     ALP_QLOGIC_XOR                      = 2,
00189     ALP_QLOGIC_NOR                      = 3,
00190     ALP_QLOGIC_NAND                     = 4,
00191 } alp_q_logic_t;
00192 #define ALP_QLOGIC(v)                   (((v-1) & 0x03) << 6)
00193 
00194 typedef enum {
00195     ALP_QDATA_SIGNED                    = 0,
00196     ALP_QDATA_UNSIGNED                  = 1
00197 } alp_q_data_t;
00198 #define ALP_QDATA(v)                    (((v) & 1) << 3)
00199 #define ALP_QMASK(v)                    (((v) & 1) << 4)
00200 
00201 typedef enum {
00202     ALP_QTYPE_NONVOID                   = 0, // This is better done by "EXIST"
00203     ALP_QTYPE_ACOMP_ZERO                = 1,
00204     ALP_QTYPE_ACOMP_IMMEDIATE           = 2,
00205     ALP_QTYPE_ACOMP_FILE                = 3,
00206     ALP_QTYPE_INRANGE                   = 4,
00207     ALP_QTYPE_STR_TOKEN                 = 7  //
00208 }alp_q_type_t;
00209 #define ALP_QTYPE(v)                   (((v) & 7) << 5)
00210 
00211 typedef enum {
00212     /// Disable all URCs on requesting ITF
00213     ALP_URC_TYPE_NONE                   = 0xFF,
00214     /// Enable Link Quality (on IFID) URCs on requesting ITF
00215     ALP_URC_TYPE_LQUAL                  = 0,
00216     /// Enable Link Down (on IFID) URCs on requesting ITF
00217     ALP_URC_TYPE_LDOWN                  = 1,
00218     /// Enable system/modem URC 
00219     /// XXX Could enable subtypes, but API does not allow it
00220     ALP_URC_TYPE_BUSY                   = 2,
00221     /// Enable Interface BUSY messages
00222     ALP_URC_TYPE_ITF_BUSY               = 3,
00223     /// XXX system/modem URC with parameter
00224     // ALP_URC_TYPE_SYS
00225 
00226     ALP_URC_TYPE_QTY,
00227 
00228 } alp_urc_type_t ;
00229 
00230 TYPEDEF_STRUCT_PACKED {
00231     u8                  perm;
00232     u8                  prop;
00233     u8                  afid;
00234     u8                  ifid;
00235     u32                 size; // XXX Big Endian
00236     u32                 alloc;// XXX Big Endian
00237 } alp_file_header_t;
00238 #define ALP_FILE_HEADER_SIZE    (sizeof(alp_file_header_t))
00239 
00240 // RESPONSES Building helpers
00241 // ======================================================================
00242 #define ALP_RSP_STATUS_SIZE         (3)     // OPCODE + ACTION_ID + ERR
00243 #define ALP_RSP_F_PROP_SIZE         (2+ALP_FILE_HEADER_SIZE)    // OPCODE + FID + 12xDATA
00244 #define ALP_LFIELD_SIZE(a)          (((a) <= 0x3F)      ? 1 : \
00245                                     (((a) <= 0x3FFF)    ? 2 : \
00246                                     (((a) <= 0x3FFFFF)  ? 3 : 4)))
00247 
00248 // ACTIONS Building helpers
00249 // ----------------------------------------------------------------------
00250 // Usual arguments:
00251 // _p   : pointer to the output string buffer (incremented by the macro)
00252 // _r   : ALP response Flag (true/false)
00253 // _fid : File ID
00254 // _o   : Access Offset
00255 // _l   : Access Length
00256 // _m   : Mask
00257 // _v   : Immediate value
00258 // ======================================================================
00259 #define ALP_ACTION_NOP_SIZE                     (1)
00260 #define ALP_ACTION_NOP(_p,_r)   do {\
00261     *(p)++ = (_r)?ALP_OPCODE_NOP+ALP_OPCODE_RESP:ALP_OPCODE_NOP;\
00262     } while(0)
00263 
00264 #define ALP_ACTION_TAG_SIZE                     (2)
00265 #define ALP_ACTION_TAG(p,tag,eop) do {\
00266     *(p)++ = (eop)?ALP_OPCODE_TAG+ALP_OPCODE_EOP:ALP_OPCODE_TAG;\
00267     *(p)++ = (tag);\
00268     } while(0)
00269 
00270 #define ALP_ACTION_F_RD_DATA_SIZE(_o,_l)        (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l))
00271 #define ALP_ACTION_F_RD_DATA_SIZE_MAX           (2+4+4)
00272 #define ALP_ACTION_F_RD_DATA(_p,_r,_fid,_o,_l) do {\
00273     *(_p)++ = (_r)?ALP_OPCODE_F_RD_DATA+ALP_OPCODE_RESP:ALP_OPCODE_F_RD_DATA;\
00274     *(_p)++ = (_fid);\
00275     (_p) += alp_encode_length(_p,_o);\
00276     (_p) += alp_encode_length(_p,_l);\
00277     } while(0)
00278 
00279 #define ALP_ACTION_F_RD_PROP_SIZE               (2)
00280 #define ALP_ACTION_F_RD_PROP(_p,_r,_fid) do {\
00281     *(_p)++ = (_r)?ALP_OPCODE_F_RD_PROP+ALP_OPCODE_RESP:ALP_OPCODE_F_RD_PROP;\
00282     *(_p)++ = (_fid);\
00283     } while(0)
00284 
00285 #define ALP_ACTION_F_WR_DATA_SIZE(_o,_l)        (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l)+(_l))
00286 #define ALP_ACTION_F_WR_DATA_SIZE_MAX(_l)       (2+4+4+(_l))
00287 #define ALP_ACTION_F_WR_DATA(_p,_r,_fid,_o,_l,_data) do {\
00288     *(_p)++ = (_r)?ALP_OPCODE_F_WR_DATA+ALP_OPCODE_RESP:ALP_OPCODE_F_WR_DATA;\
00289     *(_p)++ = (_fid);\
00290     (_p) += alp_encode_length(_p,_o);\
00291     (_p) += alp_encode_length(_p,_l);\
00292     memcpy((_p),_data,_l);(_p) += (_l);\
00293     } while(0)
00294 
00295 #define ALP_ACTION_F_WR_FLUSH_SIZE(_o,_l)       (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l)+(_l))
00296 #define ALP_ACTION_F_WR_FLUSH_SIZE_MAX(_l)      (2+4+(_l))
00297 #define ALP_ACTION_F_WR_FLUSH(_p,_r,_fid,_o,_l,_data) do {\
00298     *(_p)++ = (_r)?ALP_OPCODE_F_WR_FLUSH+ALP_OPCODE_RESP:ALP_OPCODE_F_WR_FLUSH;\
00299     *(_p)++ = (_fid);\
00300     (_p) += alp_encode_length(_p,_o);\
00301     (_p) += alp_encode_length(_p,_l);\
00302     memcpy((_p),_data,_l);(_p) += (_l);\
00303     } while(0)
00304 
00305 #define ALP_ACTION_F_WR_PROP_SIZE_MAX           (2+2+sizeof(alp_file_header_t))
00306 #define ALP_ACTION_F_WR_PROP(_p,_r,_fid,_o,_l,_data)  do {\
00307     *(_p)++ = (_r)?ALP_OPCODE_F_WR_PROP+ALP_OPCODE_RESP:ALP_OPCODE_F_WR_PROP;\
00308     *(_p)++ = (_fid);\
00309     *(_p)++ = (_o);\
00310     *(_p)++ = (_l);\
00311     memcpy((_p),(u8*)(_data),(_l));(_p) += (_l);\
00312     } while(0)
00313 
00314 #define ALP_ACTION_F_TOUCH_SIZE(_o,_l)          (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l))
00315 #define ALP_ACTION_F_TOUCH_SIZE_MAX             (2+4+4)
00316 #define ALP_ACTION_F_TOUCH(_p,_r,_fid,_o,_l)   do {\
00317     *(_p)++ = (_r)?ALP_OPCODE_F_TOUCH+ALP_OPCODE_RESP:ALP_OPCODE_F_TOUCH;\
00318     *(_p)++ = (_fid);\
00319     (_p) += alp_encode_length(_p,_o);\
00320     (_p) += alp_encode_length(_p,_l);\
00321     } while(0)
00322 
00323 #define ALP_ACTION_F_EXIST_SIZE                 (2)
00324 #define ALP_ACTION_F_EXIST(_p,_r,_fid)   do {\
00325     *(_p)++ = (_r)?ALP_OPCODE_F_EXIST+ALP_OPCODE_RESP:ALP_OPCODE_F_EXIST;\
00326     *(_p)++ = (_fid);\
00327     } while(0)
00328 
00329 #define ALP_ACTION_F_DELETE_SIZE                (2)
00330 #define ALP_ACTION_F_DELETE(_p,_r,_fid)  do {\
00331     *(_p)++ = (_r)?ALP_OPCODE_F_DELETE+ALP_OPCODE_RESP:ALP_OPCODE_F_DELETE;\
00332     *(_p)++ = (_fid);\
00333     } while(0)
00334 
00335 #define ALP_ACTION_F_FLUSH_SIZE                 (2)
00336 #define ALP_ACTION_F_FLUSH(_p,_r,_fid)   do {\
00337     *(_p)++ = (_r)?ALP_OPCODE_F_FLUSH+ALP_OPCODE_RESP:ALP_OPCODE_F_FLUSH;\
00338     *(_p)++ = (_fid);\
00339     } while(0)
00340 
00341 #define ALP_ACTION_F_CREATE_SIZE                (2+sizeof(alp_file_header_t))
00342 #define ALP_ACTION_F_CREATE(_p,_r,_fid,_hdr)  do {\
00343     *(_p)++ = (_r)?ALP_OPCODE_F_CREATE+ALP_OPCODE_RESP:ALP_OPCODE_F_CREATE;\
00344     *(_p)++ = (_fid);\
00345     memcpy((_p),(u8*)(_hdr),sizeof(alp_file_header_t));(_p) += sizeof(alp_file_header_t);\
00346     } while(0)
00347 
00348 #define ALP_PERM_REQ_USER                       0
00349 #define ALP_PERM_REQ_ROOT                       1
00350 
00351 // Wizzilab's specific Authentication-Protocol-Id
00352 #define ALP_WIZZILAB_AUTH_PROTOCOL_ID           42
00353 #define ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE   8
00354 #define ALP_ACTION_PERM_REQ_OFFSET              (3+ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE)
00355 #define ALP_ACTION_PERM_REQ_SIZE(_l)            (ALP_ACTION_PERM_REQ_OFFSET+(_l))
00356 #define ALP_ACTION_PERM_REQ(_p,_r,_role)   do {\
00357     *(_p)++ = (_r)?ALP_OPCODE_PERM_REQ+ALP_OPCODE_RESP:ALP_OPCODE_PERM_REQ;\
00358     *(_p)++ = (_role);\
00359     *(_p)++ = ALP_WIZZILAB_AUTH_PROTOCOL_ID;\
00360     } while(0)
00361 
00362 // Wizzilab's specific Challenge-Encryption-Authentication-Protocol-Id
00363 #define ALP_WIZZILAB_CHAL_PROTOCOL_ID           43
00364 #define ALP_WIZZILAB_CHAL_PROTOCOL_TOKEN_SIZE   ALP_WIZZILAB_AUTH_PROTOCOL_TOKEN_SIZE
00365 
00366 #define ALP_ACTION_URCC_SIZE(t)                 ((t==ALP_URC_TYPE_NONE)?2:4)
00367 #define ALP_ACTION_URCC_EN(_p,_r,_type,_ifid,_cfg)  do {\
00368     *(_p)++ = (_r)?ALP_OPCODE_URCC+ALP_OPCODE_GROUP+ALP_OPCODE_RESP:ALP_OPCODE_URCC+ALP_OPCODE_GROUP;\
00369     *(_p)++ = (_type);\
00370     if((_type)==ALP_URC_TYPE_LQUAL || (_type)==ALP_URC_TYPE_LDOWN)\
00371     {\
00372         *(_p)++ = (_ifid);\
00373         *(_p)++ = (_cfg);\
00374     }\
00375     else if((_type)==ALP_URC_TYPE_ITF_BUSY)\
00376     {\
00377         *(_p)++ = (_ifid);\
00378     }\
00379     } while(0)
00380 
00381 #define ALP_ACTION_URCC_DIS(_p,_r,_type,_ifid,_cfg)  do {\
00382     *(_p)++ = (_r)?ALP_OPCODE_URCC+ALP_OPCODE_RESP:ALP_OPCODE_URCC;\
00383     *(_p)++ = (_type);\
00384     if((_type)==ALP_URC_TYPE_LQUAL || (_type)==ALP_URC_TYPE_LDOWN)\
00385     {\
00386         *(_p)++ = (_ifid);\
00387         *(_p)++ = (_cfg);\
00388     }\
00389     else if((_type)==ALP_URC_TYPE_ITF_BUSY)\
00390     {\
00391         *(_p)++ = (_ifid);\
00392     }\
00393     } while(0)
00394 
00395 #define ALP_ACTION_FORWARD_SIZE(s)         (1+(s))
00396 #define ALP_ACTION_FORWARD(p,itf,itfs)    do {\
00397     *(p)++ = ALP_OPCODE_FORWARD | ALP_OPCODE_RESP;\
00398     memcpy((p),(itf),(itfs));(p) += (itfs);\
00399     } while(0)
00400 
00401 #define ALP_ACTION_RSP_F_DATA_SIZE(_o,_l)           (2+ALP_LFIELD_SIZE(_o)+ALP_LFIELD_SIZE(_l)+(_l))
00402 #define ALP_ACTION_RSP_F_DATA_SIZE_MAX(_l)          (2+4+4+(_l))
00403 #define ALP_ACTION_RSP_F_DATA(_p,_fid,_o,_l,_data)  do {\
00404     *(_p)++ = ALP_OPCODE_RSP_F_DATA;\
00405     *(_p)++ = (_fid);\
00406     (_p) += alp_encode_length(_p,_o);\
00407     (_p) += alp_encode_length(_p,_l);\
00408     memcpy((_p),(u8*)(_data),(_l));(_p) += (_l);\
00409     } while(0)
00410 
00411 #define ALP_ACTION_RSP_F_PROP_SIZE                  (2+ALP_FILE_HEADER_SIZE)
00412 #define ALP_ACTION_RSP_F_PROP(_p,_fid,_hdr)  do {\
00413     *(_p)++ = ALP_OPCODE_RSP_F_PROP;\
00414     *(_p)++ = (_fid);\
00415     memcpy((_p),(u8*)(_hdr),ALP_FILE_HEADER_SIZE);(_p) += ALP_FILE_HEADER_SIZE;\
00416     } while(0)
00417 
00418 #define ALP_ACTION_RSP_STATUS_SIZE                  (3)
00419 #define ALP_ACTION_RSP_STATUS(_p,_a,_s)  do {\
00420     *(_p)++ = ALP_OPCODE_RSP_STATUS;\
00421     *(_p)++ = (_a);\
00422     *(_p)++ = (_s);\
00423     } while(0)
00424 
00425 #define ALP_ACTION_RSP_TAG_SIZE                     (2)
00426 #define ALP_ACTION_RSP_TAG(_p,_val,_eop,_err)  do {\
00427     u8 tmp = ALP_OPCODE_RSP_TAG;\
00428     tmp |= (_eop)?ALP_OPCODE_EOP:0;\
00429     tmp |= (_err)?ALP_OPCODE_ERR:0;\
00430     *(_p)++ = tmp;\
00431     *(_p)++ = (_val);\
00432     } while(0)
00433 
00434 #define ALP_ACTION_EXT_SIZE(_argc)                  (3+(_argc))
00435 #define ALP_ACTION_EXT(_p,_r,_op,_argc)    do {\
00436     *(_p)++ = (_r)?ALP_OPCODE_EXT+ALP_OPCODE_RESP:ALP_OPCODE_EXT;\
00437     *(_p)++ = (_op);\
00438     *(_p)++ = (_argc);\
00439     } while(0)
00440 
00441 // WIZZILAB Specific Extensions
00442 #define _ALP_ACTION_ACTIVATE_ITF_SIZE               (4)
00443 #define ALP_ACTION_ACTIVATE_ITF_SIZE                (ALP_ACTION_EXT_SIZE(_ALP_ACTION_ACTIVATE_ITF_SIZE))
00444 #define ALP_ACTION_ACTIVATE_ITF(_p,_r,_en,_type,_dev,_ifid,_flag)    do {\
00445     ALP_ACTION_EXT(_p,_r,(_en)?ALP_EXTOPCODE_ITF_START:ALP_EXTOPCODE_ITF_STOP,_ALP_ACTION_ACTIVATE_ITF_SIZE);\
00446     *(p)++ = _type;\
00447     *(p)++ = _dev;\
00448     *(p)++ = _ifid;\
00449     *(p)++ = _flag;\
00450     } while(0)
00451 
00452 #define _ALP_ACTION_F_DECLARE_SIZE                  (1+sizeof(alp_file_header_t))
00453 #define ALP_ACTION_F_DECLARE_SIZE                   (ALP_ACTION_EXT_SIZE(_ALP_ACTION_F_DECLARE_SIZE))
00454 #define ALP_ACTION_F_DECLARE(_p,_r,_fid,_hdr,_dist) do {\
00455     ALP_ACTION_EXT(_p,_r,(_dist)?ALP_EXTOPCODE_F_DECLARE+ALP_EXTOPCODE_DISTANT:ALP_EXTOPCODE_F_DECLARE,_ALP_ACTION_F_DECLARE_SIZE);\
00456     *(_p)++ = (_fid);\
00457     memcpy((_p),(u8*)(_hdr),sizeof(alp_file_header_t));(_p) += sizeof(alp_file_header_t);\
00458     } while(0)
00459 
00460 
00461 // Simple "report/notify" actions. For both, FID,Offset and size will be
00462 // substituted thanks to specific Offset-Operand token
00463 #define ALP_ACTION_REPORT_FULL_FILE { \
00464     ALP_OPCODE_F_RD_DATA | ALP_OPCODE_RESP,\
00465     0, HAL_U16_BE_DEPOSIT(0x4000), 0 }
00466 
00467 #define ALP_ACTION_REPORT_PART_FILE { \
00468     ALP_OPCODE_F_RD_DATA | ALP_OPCODE_RESP,\
00469     0, HAL_U16_BE_DEPOSIT(0x8000), 0 }
00470 
00471 // Simple Query actions
00472 /// Match immediate value to file value
00473 #define ALP_ACTION_QUERY_EQVAL_SIZE(_o,_l,_mbit)    (4+ALP_LFIELD_SIZE(_o)+(1+(_mbit))*(_l))
00474 #define ALP_ACTION_QUERY_EQVAL(_p,_m,_v,_fid,_o,_l)   do {\
00475     u8 _mbit = (_m) ? 1 : 0;\
00476     *(_p)++ = ALP_OPCODE_QUERY;\
00477     *(_p)++ = ALP_QCOMP(ALP_QCOMP_EQ) | ALP_QDATA(ALP_QDATA_UNSIGNED) | ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_ACOMP_IMMEDIATE);\
00478     *(_p)++ = _l;\
00479     if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
00480     memcpy((_p),&(_v),_l);(_p) += (_l);\
00481     *(_p)++ = _fid;\
00482     (_p) += alp_encode_length(_p,_o);\
00483     } while(0)
00484 
00485 // Query with break actions
00486 /// Match immediate value to file value
00487 #define ALP_ACTION_QBREAK_SIZE(_o,_l,_mbit)    (4+ALP_LFIELD_SIZE(_o)+(1+(_mbit))*(_l))
00488 
00489 /// Compare immediate value to file value
00490 #define ALP_ACTION_QBREAK_COMP(_p,_m,_v,_c,_fid,_o,_l,_g)   do {\
00491     u8 _mbit = (_m) ? 1 : 0;\
00492     *(_p)++ = ALP_OPCODE_QBREAK | ((_g)? ALP_OPCODE_GROUP: 0);\
00493     *(_p)++ = ALP_QCOMP(_c) | ALP_QDATA(ALP_QDATA_UNSIGNED) | ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_ACOMP_IMMEDIATE);\
00494     *(_p)++ = _l;\
00495     if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
00496     memcpy((_p),&(_v),_l);(_p) += (_l);\
00497     *(_p)++ = _fid;\
00498     (_p) += alp_encode_length(_p,_o);\
00499     } while(0)
00500 
00501 #define ALP_ACTION_QBREAK_STRTOK(_p,_m,_v,_fid,_o,_l,_g)   do {\
00502     u8 _mbit = (_m) ? 1 : 0;\
00503     *(_p)++ = ALP_OPCODE_QBREAK | ((_g)? ALP_OPCODE_GROUP: 0);\
00504     *(_p)++ = ALP_QMASK(_mbit) | ALP_QTYPE(ALP_QTYPE_STR_TOKEN) | ALP_QSTR_PARAM(0);\
00505     *(_p)++ = _l;\
00506     if (_mbit) {memcpy((_p),&(_m),_l);(_p) += (_l);}\
00507     memcpy((_p),&(_v),_l);(_p) += (_l);\
00508     *(_p)++ = _fid;\
00509     (_p) += alp_encode_length(_p,_o);\
00510     } while(0)
00511 
00512 #define ALP_ACTION_QLOGIC_SIZE   1
00513 #define ALP_ACTION_QLOGIC(_p,_l) do {\
00514         *(_p)++ = ALP_OPCODE_LOGIC | ALP_QLOGIC(_l);\
00515         } while(0)
00516 
00517 #endif // __ALP_SPEC_H__