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 *
22 *  This file contains the LLCP definitions
23 *
24 ******************************************************************************/
25#ifndef LLCP_DEFS_H
26#define LLCP_DEFS_H
27
28/*
29** LLCP PDU Descriptions
30*/
31
32#define LLCP_PDU_HEADER_SIZE    2       /* DSAP:PTYPE:SSAP excluding Sequence */
33
34#define LLCP_GET_DSAP(u16)  (((u16) & 0xFC00) >> 10)
35#define LLCP_GET_PTYPE(u16) (((u16) & 0x03C0) >> 6)
36#define LLCP_GET_SSAP(u16)  (((u16) & 0x003F))
37
38#define LLCP_GET_PDU_HEADER(dsap, ptype, ssap) (((UINT16) (dsap) << 10) | ((UINT16) (ptype) << 6) | (UINT16) (ssap))
39
40#define LLCP_GET_NS(u8) ((UINT8)(u8) >> 4)
41#define LLCP_GET_NR(u8) ((UINT8)(u8) & 0x0F)
42#define LLCP_GET_SEQUENCE(NS, NR) (((UINT8) (NS) << 4) | (UINT8) (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) (u8) >> 7) & 0x01)
85#define LLCP_GET_FRMR_I_ERROR_FLAG(u8) (((UINT8) (u8) >> 6) & 0x01)
86#define LLCP_GET_FRMR_R_ERROR_FLAG(u8) (((UINT8) (u8) >> 5) & 0x01)
87#define LLCP_GET_FRMR_S_ERROR_FLAG(u8) (((UINT8) (u8) >> 4) & 0x01)
88#define LLCP_GET_FRMR_PTYPE(u8)        ((UINT8) (u8) & 0x0F)
89#define LLCP_GET_FRMR_VS(u16)          (((UINT16) (u16) >> 12) & 0x000F)
90#define LLCP_GET_FRMR_VR(u16)          (((UINT16) (u16) >>  8) & 0x000F)
91#define LLCP_GET_FRMR_VSA(u16)         (((UINT16) (u16) >>  4) & 0x000F)
92#define LLCP_GET_FRMR_VRA(u16)         (((UINT16) (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) (u8) >> 4) & 0x0F)
102#define LLCP_GET_MINOR_VERSION(u8)     ((UINT8) (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.1 */
108#define LLCP_VERSION_MAJOR  0x01
109#define LLCP_VERSION_MINOR  0x01
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#define LLCP_WKS_MASK_OBEX  0x0008  /* OBEX over LLCP Binding "urn:nfc:sn:obex" */
128#define LLCP_WKS_MASK_SNEP  0x0010  /* Simple NDEP Exchange Protocol "urn:nfc:sn:snep" */
129
130/* Well-Known Service Access Points */
131#define LLCP_SAP_LM         0x00    /* Link Management */
132#define LLCP_SAP_SDP        0x01    /* Service Discovery "urn:nfc:sn:sdp" */
133#define LLCP_SAP_IP         0x02    /* IP over LLCP Binding "urn:nfc:sn:ip" */
134#define LLCP_SAP_OBEX       0x03    /* OBEX over LLCP Binding "urn:nfc:sn:obex" */
135#define LLCP_SAP_SNEP       0x04    /* Simple NDEP Exchange Protocol "urn:nfc:sn:snep" */
136
137/* Link Timeout, LTO */
138#define LLCP_LTO_TYPE       0x04
139#define LLCP_LTO_LEN        0x01
140#define LLCP_DEFAULT_LTO_IN_MS    100     /* default 100ms. It should be sufficiently larget than RWT */
141#define LLCP_LTO_UNIT       10      /* 10 ms */
142#define LLCP_MAX_LTO_IN_MS  2550    /* 2550 ms; 8bits * 10ms */
143
144/* Receive Window Size, RW */
145#define LLCP_RW_TYPE        0x05
146#define LLCP_RW_LEN         0x01
147#define LLCP_DEFAULT_RW     1       /* if local LLC doesn't receive RW */
148
149/* Service Name, SN */
150#define LLCP_SN_TYPE        0x06
151
152/* Option, OPT */
153#define LLCP_OPT_TYPE       0x07
154#define LLCP_OPT_LEN        0x01
155#define LLCP_GET_OPT_LSC(u8) ((UINT8) (u8) & 0x03)
156
157/* Service Discovery Request, SDREQ */
158#define LLCP_SDREQ_TYPE     0x08
159#define LLCP_SDREQ_MIN_LEN  0x03    /* type(1 byte), length(1 byte), TID(1 byte) */
160
161/* Service Discovery Response, SDRES */
162#define LLCP_SDRES_TYPE     0x09
163#define LLCP_SDRES_LEN      0x02
164
165/* Link Service Class */
166#define LLCP_LSC_UNKNOWN    0x00
167#define LLCP_LSC_1          0x01
168#define LLCP_LSC_2          0x02
169#define LLCP_LSC_3          0x03
170
171#define LLCP_MAGIC_NUMBER_LEN       3
172#define LLCP_MAGIC_NUMBER_BYTE0     0x46
173#define LLCP_MAGIC_NUMBER_BYTE1     0x66
174#define LLCP_MAGIC_NUMBER_BYTE2     0x6D
175
176#define LLCP_SEQ_MODULO             16
177
178#define LLCP_NUM_SAPS               64
179#define LLCP_LOWER_BOUND_WK_SAP     0x00
180#define LLCP_UPPER_BOUND_WK_SAP     0x0F
181#define LLCP_LOWER_BOUND_SDP_SAP    0x10
182#define LLCP_UPPER_BOUND_SDP_SAP    0x1F
183#define LLCP_LOWER_BOUND_LOCAL_SAP  0x20
184#define LLCP_UPPER_BOUND_LOCAL_SAP  0x3F
185
186/* Max Payload */
187#define LLCP_NCI_MAX_PAYL_SIZE      254 /* Maximum Payload size, Length Reduction LRi/LRt */
188#define LLCP_NFC_DEP_HEADER_SIZE      3 /* Data exchange protocol header, 3 bytes */
189#define LLCP_MAX_PAYLOAD_SIZE       (LLCP_NCI_MAX_PAYL_SIZE - LLCP_NFC_DEP_HEADER_SIZE)
190
191#define LLCP_MAX_GEN_BYTES          48
192
193#endif  /* LLCP_DEFS_H */
194