Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2010-2014 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  This file contains the LLCP definitions
     22  *
     23  ******************************************************************************/
     24 #ifndef LLCP_DEFS_H
     25 #define LLCP_DEFS_H
     26 
     27 /*
     28 ** LLCP PDU Descriptions
     29 */
     30 
     31 #define LLCP_PDU_HEADER_SIZE 2 /* DSAP:PTYPE:SSAP excluding Sequence */
     32 
     33 #define LLCP_GET_DSAP(u16) (((u16)&0xFC00) >> 10)
     34 #define LLCP_GET_PTYPE(u16) (((u16)&0x03C0) >> 6)
     35 #define LLCP_GET_SSAP(u16) (((u16)&0x003F))
     36 
     37 #define LLCP_GET_PDU_HEADER(dsap, ptype, ssap) \
     38   (((uint16_t)(dsap) << 10) | ((uint16_t)(ptype) << 6) | (uint16_t)(ssap))
     39 
     40 #define LLCP_GET_NS(u8) ((uint8_t)(u8) >> 4)
     41 #define LLCP_GET_NR(u8) ((uint8_t)(u8)&0x0F)
     42 #define LLCP_GET_SEQUENCE(NS, NR) (((uint8_t)(NS) << 4) | (uint8_t)(NR))
     43 #define LLCP_SEQUENCE_SIZE 1
     44 
     45 #define LLCP_PDU_SYMM_TYPE 0
     46 #define LLCP_PDU_PAX_TYPE 1
     47 #define LLCP_PDU_AGF_TYPE 2
     48 #define LLCP_PDU_UI_TYPE 3
     49 #define LLCP_PDU_CONNECT_TYPE 4
     50 #define LLCP_PDU_DISC_TYPE 5
     51 #define LLCP_PDU_CC_TYPE 6
     52 #define LLCP_PDU_DM_TYPE 7
     53 #define LLCP_PDU_FRMR_TYPE 8
     54 #define LLCP_PDU_SNL_TYPE 9
     55 #define LLCP_PDU_RESERVED_1010 10
     56 #define LLCP_PDU_RESERVED_1011 11
     57 #define LLCP_PDU_I_TYPE 12
     58 #define LLCP_PDU_RR_TYPE 13
     59 #define LLCP_PDU_RNR_TYPE 14
     60 #define LLCP_PDU_RESERVED_1111 15
     61 
     62 #define LLCP_PDU_SYMM_SIZE 2
     63 #define LLCP_PDU_DISC_SIZE 2
     64 #define LLCP_PDU_DM_SIZE 3
     65 #define LLCP_PDU_FRMR_SIZE 6
     66 #define LLCP_PDU_RR_SIZE 3
     67 #define LLCP_PDU_RNR_SIZE 3
     68 #define LLCP_PDU_AGF_LEN_SIZE 2 /* 2 bytes of length in AGF PDU */
     69 
     70 #define LLCP_SAP_DM_REASON_RESP_DISC 0x00
     71 #define LLCP_SAP_DM_REASON_NO_ACTIVE_CONNECTION 0x01
     72 #define LLCP_SAP_DM_REASON_NO_SERVICE 0x02
     73 #define LLCP_SAP_DM_REASON_APP_REJECTED 0x03
     74 #define LLCP_SAP_DM_REASON_PERM_REJECT_THIS 0x10
     75 #define LLCP_SAP_DM_REASON_PERM_REJECT_ANY 0x11
     76 #define LLCP_SAP_DM_REASON_TEMP_REJECT_THIS 0x20
     77 #define LLCP_SAP_DM_REASON_TEMP_REJECT_ANY 0x21
     78 
     79 #define LLCP_FRMR_W_ERROR_FLAG 0x08 /* Well-formedness Error */
     80 #define LLCP_FRMR_I_ERROR_FLAG 0x04 /* Information Field Error */
     81 #define LLCP_FRMR_R_ERROR_FLAG 0x02 /* Receive Sequence Error */
     82 #define LLCP_FRMR_S_ERROR_FLAG 0x01 /* Send Sequence Error */
     83 
     84 #define LLCP_GET_FRMR_W_ERROR_FLAG(u8) (((uint8_t)(u8) >> 7) & 0x01)
     85 #define LLCP_GET_FRMR_I_ERROR_FLAG(u8) (((uint8_t)(u8) >> 6) & 0x01)
     86 #define LLCP_GET_FRMR_R_ERROR_FLAG(u8) (((uint8_t)(u8) >> 5) & 0x01)
     87 #define LLCP_GET_FRMR_S_ERROR_FLAG(u8) (((uint8_t)(u8) >> 4) & 0x01)
     88 #define LLCP_GET_FRMR_PTYPE(u8) ((uint8_t)(u8)&0x0F)
     89 #define LLCP_GET_FRMR_VS(u16) (((uint16_t)(u16) >> 12) & 0x000F)
     90 #define LLCP_GET_FRMR_VR(u16) (((uint16_t)(u16) >> 8) & 0x000F)
     91 #define LLCP_GET_FRMR_VSA(u16) (((uint16_t)(u16) >> 4) & 0x000F)
     92 #define LLCP_GET_FRMR_VRA(u16) (((uint16_t)(u16) >> 0) & 0x000F)
     93 
     94 /*
     95 ** LLCP Parameter Descriptions
     96 */
     97 
     98 /* Version */
     99 #define LLCP_VERSION_TYPE 0x01
    100 #define LLCP_VERSION_LEN 0x01
    101 #define LLCP_GET_MAJOR_VERSION(u8) (((uint8_t)(u8) >> 4) & 0x0F)
    102 #define LLCP_GET_MINOR_VERSION(u8) ((uint8_t)(u8)&0x0F)
    103 #define LLCP_MIN_MAJOR_VERSION 0x01
    104 #define LLCP_MIN_SNL_MAJOR_VERSION 0x01
    105 #define LLCP_MIN_SNL_MINOR_VERSION 0x01
    106 
    107 /* LLCP Version 1.2 */
    108 #define LLCP_VERSION_MAJOR 0x01
    109 #define LLCP_VERSION_MINOR 0x02
    110 #define LLCP_VERSION_VALUE ((LLCP_VERSION_MAJOR << 4) | LLCP_VERSION_MINOR)
    111 
    112 /* Maximum Information Unit Extension */
    113 #define LLCP_MIUX_TYPE 0x02
    114 #define LLCP_MIUX_LEN 0x02
    115 #define LLCP_MIUX_MASK 0x07FF /* MIUX bit 10:0 */
    116 #define LLCP_DEFAULT_MIU 128  /* if local LLC doesn't receive MIUX */
    117 #define LLCP_MAX_MIU 2175     /* 2047 (11bits) + 128 */
    118 
    119 /* Well-Known Service */
    120 #define LLCP_WKS_TYPE 0x03
    121 #define LLCP_WKS_LEN 0x02
    122 
    123 /* Well-Known Service Bitmap */
    124 #define LLCP_WKS_MASK_LM 0x0001  /* Link Management */
    125 #define LLCP_WKS_MASK_SDP 0x0002 /* Service Discovery "urn:nfc:sn:sdp" */
    126 #define LLCP_WKS_MASK_IP 0x0004  /* IP over LLCP Binding "urn:nfc:sn:ip" */
    127 /* OBEX over LLCP Binding "urn:nfc:sn:obex" */
    128 #define LLCP_WKS_MASK_OBEX 0x0008
    129 /* Simple NDEP Exchange Protocol "urn:nfc:sn:snep" */
    130 #define LLCP_WKS_MASK_SNEP 0x0010
    131 
    132 /* Well-Known Service Access Points */
    133 #define LLCP_SAP_LM 0x00  /* Link Management */
    134 #define LLCP_SAP_SDP 0x01 /* Service Discovery "urn:nfc:sn:sdp" */
    135 #define LLCP_SAP_IP 0x02  /* IP over LLCP Binding "urn:nfc:sn:ip" */
    136 /* OBEX over LLCP Binding "urn:nfc:sn:obex" */
    137 #define LLCP_SAP_OBEX 0x03
    138 /* Simple NDEP Exchange Protocol "urn:nfc:sn:snep" */
    139 #define LLCP_SAP_SNEP 0x04
    140 
    141 /* Link Timeout, LTO */
    142 #define LLCP_LTO_TYPE 0x04
    143 #define LLCP_LTO_LEN 0x01
    144 /* default 100ms. It should be sufficiently larget than RWT */
    145 #define LLCP_DEFAULT_LTO_IN_MS 100
    146 #define LLCP_LTO_UNIT 10        /* 10 ms */
    147 #define LLCP_MAX_LTO_IN_MS 2550 /* 2550 ms; 8bits * 10ms */
    148 
    149 /* Receive Window Size, RW */
    150 #define LLCP_RW_TYPE 0x05
    151 #define LLCP_RW_LEN 0x01
    152 #define LLCP_DEFAULT_RW 1 /* if local LLC doesn't receive RW */
    153 
    154 /* Service Name, SN */
    155 #define LLCP_SN_TYPE 0x06
    156 
    157 /* Option, OPT */
    158 #define LLCP_OPT_TYPE 0x07
    159 #define LLCP_OPT_LEN 0x01
    160 #define LLCP_GET_OPT_LSC(u8) ((uint8_t)(u8)&0x03)
    161 
    162 /* Service Discovery Request, SDREQ */
    163 #define LLCP_SDREQ_TYPE 0x08
    164 /* type(1 byte), length(1 byte), TID(1 byte) */
    165 #define LLCP_SDREQ_MIN_LEN 0x03
    166 
    167 /* Service Discovery Response, SDRES */
    168 #define LLCP_SDRES_TYPE 0x09
    169 #define LLCP_SDRES_LEN 0x02
    170 
    171 /* Link Service Class */
    172 #define LLCP_LSC_UNKNOWN 0x00
    173 #define LLCP_LSC_1 0x01
    174 #define LLCP_LSC_2 0x02
    175 #define LLCP_LSC_3 0x03
    176 
    177 #define LLCP_MAGIC_NUMBER_LEN 3
    178 #define LLCP_MAGIC_NUMBER_BYTE0 0x46
    179 #define LLCP_MAGIC_NUMBER_BYTE1 0x66
    180 #define LLCP_MAGIC_NUMBER_BYTE2 0x6D
    181 
    182 #define LLCP_SEQ_MODULO 16
    183 
    184 #define LLCP_NUM_SAPS 64
    185 #define LLCP_LOWER_BOUND_WK_SAP 0x00
    186 #define LLCP_UPPER_BOUND_WK_SAP 0x0F
    187 #define LLCP_LOWER_BOUND_SDP_SAP 0x10
    188 #define LLCP_UPPER_BOUND_SDP_SAP 0x1F
    189 #define LLCP_LOWER_BOUND_LOCAL_SAP 0x20
    190 #define LLCP_UPPER_BOUND_LOCAL_SAP 0x3F
    191 
    192 /* Max Payload */
    193 /* Maximum Payload size, Length Reduction LRi/LRt */
    194 #define LLCP_NCI_MAX_PAYL_SIZE 254
    195 /* Data exchange protocol header, 3 bytes */
    196 #define LLCP_NFC_DEP_HEADER_SIZE 3
    197 #define LLCP_MAX_PAYLOAD_SIZE \
    198   (LLCP_NCI_MAX_PAYL_SIZE - LLCP_NFC_DEP_HEADER_SIZE)
    199 
    200 #define LLCP_MAX_GEN_BYTES 48
    201 
    202 #endif /* LLCP_DEFS_H */
    203