svc_dis.c 9.83 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*************************************************************************************************/
/*!
 *  \file
 *
 *  \brief  Example Device Information Service implementation.
 *
 *  Copyright (c) 2011-2018 Arm Ltd. All Rights Reserved.
 *  ARM Ltd. confidential and proprietary.
 *
 *  IMPORTANT.  Your use of this file is governed by a Software License Agreement
 *  ("Agreement") that must be accepted in order to download or otherwise receive a
 *  copy of this file.  You may not use or copy this file for any purpose other than
 *  as described in the Agreement.  If you do not agree to all of the terms of the
 *  Agreement do not use this file and delete all copies in your possession or control;
 *  if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
 *  to any use, copying or further distribution of this software.
 */
/*************************************************************************************************/

/* card10:
 * Copied from lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_dis.c
 *
 * Contains adaptions for the card10 (e.g. manufacturer name)
 */
#include "wsf_types.h"
#include "att_api.h"
27
#include "wsf_assert.h"
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
#include "wsf_trace.h"
#include "util/bstream.h"
#include "svc_dis.h"
#include "svc_cfg.h"

/**************************************************************************************************
  Macros
**************************************************************************************************/

/*! Characteristic read permissions */
#ifndef DIS_SEC_PERMIT_READ
#define DIS_SEC_PERMIT_READ SVC_SEC_PERMIT_READ
#endif

/*! Default manufacturer name */
#define DIS_DEFAULT_MFR_NAME        "CCC"

/*! Length of default manufacturer name */
#define DIS_DEFAULT_MFR_NAME_LEN    3

/*! Default model number */
#define DIS_DEFAULT_MODEL_NUM       "1"

/*! Length of default model number */
#define DIS_DEFAULT_MODEL_NUM_LEN   1

/*! Default serial number */
#define DIS_DEFAULT_SERIAL_NUM      "1"

/*! Length of default serial number */
#define DIS_DEFAULT_SERIAL_NUM_LEN  1

/*! Default firmware revision */
#define DIS_DEFAULT_FW_REV          "<git hash>"

/*! Length of default firmware revision */
#define DIS_DEFAULT_FW_REV_LEN      10

/*! Default hardware revision */
#define DIS_DEFAULT_HW_REV          "1"

/*! Length of default hardware revision */
#define DIS_DEFAULT_HW_REV_LEN      1

/*! Default software revision */
#define DIS_DEFAULT_SW_REV          "1"

/*! Length of default software revision */
#define DIS_DEFAULT_SW_REV_LEN      1

/**************************************************************************************************
 Service variables
**************************************************************************************************/

/* Device information service declaration */
static const uint8_t disValSvc[] = {UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)};
static const uint16_t disLenSvc = sizeof(disValSvc);

/* Manufacturer name string characteristic */
static const uint8_t disValMfrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_MFR_HDL), UINT16_TO_BYTES(ATT_UUID_MANUFACTURER_NAME)};
static const uint16_t disLenMfrCh = sizeof(disValMfrCh);

/* Manufacturer name string */
static const uint8_t disUuMfr[] = {UINT16_TO_BYTES(ATT_UUID_MANUFACTURER_NAME)};
static uint8_t disValMfr[DIS_MAXSIZE_MFR_ATT] = DIS_DEFAULT_MFR_NAME;
static uint16_t disLenMfr = DIS_DEFAULT_MFR_NAME_LEN;

/* System ID characteristic */
static const uint8_t disValSidCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SID_HDL), UINT16_TO_BYTES(ATT_UUID_SYSTEM_ID)};
static const uint16_t disLenSidCh = sizeof(disValSidCh);

/* System ID */
static const uint8_t disUuSid[] = {UINT16_TO_BYTES(ATT_UUID_SYSTEM_ID)};
static uint8_t disValSid[DIS_SIZE_SID_ATT] = {0x01, 0x02, 0x03, 0x04, 0x05, UINT16_TO_BYTE0(HCI_ID_ARM), UINT16_TO_BYTE1(HCI_ID_ARM), 0x00};
static const uint16_t disLenSid = sizeof(disValSid);

/* Model number string characteristic */
static const uint8_t disValMnCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_MN_HDL), UINT16_TO_BYTES(ATT_UUID_MODEL_NUMBER)};
static const uint16_t disLenMnCh = sizeof(disValMnCh);

/* Model number string */
static const uint8_t disUuMn[] = {UINT16_TO_BYTES(ATT_UUID_MODEL_NUMBER)};
static uint8_t disValMn[DIS_MAXSIZE_MN_ATT] = DIS_DEFAULT_MODEL_NUM;
static uint16_t disLenMn = DIS_DEFAULT_MODEL_NUM_LEN;

/* Serial number string characteristic */
static const uint8_t disValSnCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SN_HDL), UINT16_TO_BYTES(ATT_UUID_SERIAL_NUMBER)};
static const uint16_t disLenSnCh = sizeof(disValSnCh);

/* Serial number string */
static const uint8_t disUuSn[] = {UINT16_TO_BYTES(ATT_UUID_SERIAL_NUMBER)};
static uint8_t disValSn[DIS_MAXSIZE_SN_ATT] = DIS_DEFAULT_SERIAL_NUM;
static uint16_t disLenSn = DIS_DEFAULT_SERIAL_NUM_LEN;

/* Firmware revision string characteristic */
static const uint8_t disValFwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_FWR_HDL), UINT16_TO_BYTES(ATT_UUID_FIRMWARE_REV)};
static const uint16_t disLenFwrCh = sizeof(disValFwrCh);

/* Firmware revision string */
static const uint8_t disUuFwr[] = {UINT16_TO_BYTES(ATT_UUID_FIRMWARE_REV)};
static uint8_t disValFwr[DIS_MAXSIZE_FWR_ATT] = DIS_DEFAULT_FW_REV;
static uint16_t disLenFwr = DIS_DEFAULT_FW_REV_LEN;

/* Hardware revision string characteristic */
static const uint8_t disValHwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_HWR_HDL), UINT16_TO_BYTES(ATT_UUID_HARDWARE_REV)};
static const uint16_t disLenHwrCh = sizeof(disValHwrCh);

/* Hardware revision string */
static const uint8_t disUuHwr[] = {UINT16_TO_BYTES(ATT_UUID_HARDWARE_REV)};
static uint8_t disValHwr[DIS_MAXSIZE_HWR_ATT] = DIS_DEFAULT_HW_REV;
static uint16_t disLenHwr = DIS_DEFAULT_HW_REV_LEN;

/* Software revision string characteristic */
static const uint8_t disValSwrCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_SWR_HDL), UINT16_TO_BYTES(ATT_UUID_SOFTWARE_REV)};
static const uint16_t disLenSwrCh = sizeof(disValSwrCh);

/* Software revision string */
static const uint8_t disUuSwr[] = {UINT16_TO_BYTES(ATT_UUID_SOFTWARE_REV)};
static uint8_t disValSwr[DIS_MAXSIZE_SWR_ATT] = DIS_DEFAULT_SW_REV;
static uint16_t disLenSwr = DIS_DEFAULT_SW_REV_LEN;

/* Registration certificate data characteristic */
static const uint8_t disValRcdCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(DIS_RCD_HDL), UINT16_TO_BYTES(ATT_UUID_11073_CERT_DATA)};
static const uint16_t disLenRcdCh = sizeof(disValRcdCh);

/* Registration certificate data */
static const uint8_t disUuRcd[] = {UINT16_TO_BYTES(ATT_UUID_11073_CERT_DATA)};
static uint8_t disValRcd[DIS_SIZE_RCD_ATT] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static const uint16_t disLenRcd = sizeof(disValRcd);

/* Attribute list for dis group */
static const attsAttr_t disList[] =
{
  {
    attPrimSvcUuid,
    (uint8_t *) disValSvc,
    (uint16_t *) &disLenSvc,
    sizeof(disValSvc),
    0,
    ATTS_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValMfrCh,
    (uint16_t *) &disLenMfrCh,
    sizeof(disValMfrCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuMfr,
    (uint8_t *) disValMfr,
    (uint16_t *) &disLenMfr,
    sizeof(disValMfr),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValSidCh,
    (uint16_t *) &disLenSidCh,
    sizeof(disValSidCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuSid,
    disValSid,
    (uint16_t *) &disLenSid,
    sizeof(disValSid),
    0,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValMnCh,
    (uint16_t *) &disLenMnCh,
    sizeof(disValMnCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuMn,
    (uint8_t *) disValMn,
    (uint16_t *) &disLenMn,
    sizeof(disValMn),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValSnCh,
    (uint16_t *) &disLenSnCh,
    sizeof(disValSnCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuSn,
    (uint8_t *) disValSn,
    (uint16_t *) &disLenSn,
    sizeof(disValSn),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValFwrCh,
    (uint16_t *) &disLenFwrCh,
    sizeof(disValFwrCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuFwr,
    (uint8_t *) disValFwr,
    (uint16_t *) &disLenFwr,
    sizeof(disValFwr),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValHwrCh,
    (uint16_t *) &disLenHwrCh,
    sizeof(disValHwrCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuHwr,
    (uint8_t *) disValHwr,
    (uint16_t *) &disLenHwr,
    sizeof(disValHwr),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValSwrCh,
    (uint16_t *) &disLenSwrCh,
    sizeof(disValSwrCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuSwr,
    (uint8_t *) disValSwr,
    (uint16_t *) &disLenSwr,
    sizeof(disValSwr),
    ATTS_SET_VARIABLE_LEN,
    DIS_SEC_PERMIT_READ
  },
  {
    attChUuid,
    (uint8_t *) disValRcdCh,
    (uint16_t *) &disLenRcdCh,
    sizeof(disValRcdCh),
    0,
    ATTS_PERMIT_READ
  },
  {
    disUuRcd,
    (uint8_t *) disValRcd,
    (uint16_t *) &disLenRcd,
    sizeof(disValRcd),
    0,
    DIS_SEC_PERMIT_READ
  },
};

/* DIS group structure */
static attsGroup_t svcDisGroup =
{
  NULL,
  (attsAttr_t *) disList,
  NULL,
  NULL,
  DIS_START_HDL,
  DIS_END_HDL
};

310
WSF_CT_ASSERT(((sizeof(disList) / sizeof(disList[0])) == DIS_END_HDL - DIS_START_HDL + 1));
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/*************************************************************************************************/
/*!
 *  \brief  Add the services to the attribute server.
 *
 *  \return None.
 */
/*************************************************************************************************/
void SvcDisAddGroup(void)
{
  AttsAddGroup(&svcDisGroup);
}

/*************************************************************************************************/
/*!
 *  \brief  Remove the services from the attribute server.
 *
 *  \return None.
 */
/*************************************************************************************************/
void SvcDisRemoveGroup(void)
{
  AttsRemoveGroup(DIS_START_HDL);
}