3 * BlueZ - Bluetooth protocol stack for Linux
5 * Copyright (C) 2011 Nokia Corporation
6 * Copyright (C) 2011 Marcel Holtmann <marcel@holtmann.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <bluetooth/uuid.h>
38 #include "attrib-server.h"
41 #define IMMEDIATE_ALERT_SVC_UUID 0x1802
42 #define LINK_LOSS_SVC_UUID 0x1803
43 #define TX_POWER_SVC_UUID 0x1804
44 #define ALERT_LEVEL_CHR_UUID 0x2A06
45 #define POWER_LEVEL_CHR_UUID 0x2A07
53 static uint16_t tx_power_handle;
55 static void register_link_loss(void)
57 uint16_t start_handle, h;
58 const int svc_size = 3;
62 /* FIXME: Provide the adapter in next function */
63 start_handle = attrib_db_find_avail(NULL, svc_size);
64 if (start_handle == 0) {
65 error("Not enough free handles to register service");
69 DBG("start_handle=0x%04x", start_handle);
73 /* Primary service definition */
74 bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
75 att_put_u16(LINK_LOSS_SVC_UUID, &atval[0]);
76 /* FIXME: Provide the adapter in next function */
77 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
79 /* Alert level characteristic */
80 bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
81 atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_WRITE;
82 att_put_u16(h + 1, &atval[1]);
83 att_put_u16(ALERT_LEVEL_CHR_UUID, &atval[3]);
84 /* FIXME: Provide the adapter in next function */
85 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
87 /* Alert level value */
88 bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
89 att_put_u8(NO_ALERT, &atval[0]);
90 /* FIXME: Provide the adapter in next function */
91 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);
93 g_assert(h - start_handle == svc_size);
96 static void register_tx_power(void)
98 uint16_t start_handle, h;
99 const int svc_size = 4;
103 /* FIXME: Provide the adapter in next function */
104 start_handle = attrib_db_find_avail(NULL, svc_size);
105 if (start_handle == 0) {
106 error("Not enough free handles to register service");
110 DBG("start_handle=0x%04x", start_handle);
114 /* Primary service definition */
115 bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
116 att_put_u16(TX_POWER_SVC_UUID, &atval[0]);
117 /* FIXME: Provide the adapter in next function */
118 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
120 /* Power level characteristic */
121 bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
122 atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_NOTIFY;
123 att_put_u16(h + 1, &atval[1]);
124 att_put_u16(POWER_LEVEL_CHR_UUID, &atval[3]);
125 /* FIXME: Provide the adapter in next function */
126 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
128 /* Power level value */
129 bt_uuid16_create(&uuid, POWER_LEVEL_CHR_UUID);
130 att_put_u8(0x00, &atval[0]);
132 /* FIXME: Provide the adapter in next function */
133 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1);
135 /* Client characteristic configuration */
136 bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
139 /* FIXME: Provide the adapter in next function */
140 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 2);
142 g_assert(h - start_handle == svc_size);
145 static void register_immediate_alert(void)
147 uint16_t start_handle, h;
148 const int svc_size = 3;
152 /* FIXME: Provide the adapter in next function */
153 start_handle = attrib_db_find_avail(NULL, svc_size);
154 if (start_handle == 0) {
155 error("Not enough free handles to register service");
159 DBG("start_handle=0x%04x", start_handle);
163 /* Primary service definition */
164 bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
165 att_put_u16(IMMEDIATE_ALERT_SVC_UUID, &atval[0]);
166 /* FIXME: Provide the adapter in next function */
167 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);
169 /* Alert level characteristic */
170 bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
171 atval[0] = ATT_CHAR_PROPER_WRITE_WITHOUT_RESP;
172 att_put_u16(h + 1, &atval[1]);
173 att_put_u16(ALERT_LEVEL_CHR_UUID, &atval[3]);
174 /* FIXME: Provide the adapter in next function */
175 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);
177 /* Alert level value */
178 bt_uuid16_create(&uuid, ALERT_LEVEL_CHR_UUID);
179 att_put_u8(NO_ALERT, &atval[0]);
180 /* FIXME: Provide the adapter in next function */
181 attrib_db_add(NULL, h++, &uuid, ATT_NONE, ATT_NONE, atval, 1);
183 g_assert(h - start_handle == svc_size);
186 int reporter_init(void)
188 if (!main_opts.attrib_server) {
189 DBG("Attribute server is disabled");
193 DBG("Proximity Reporter");
195 register_link_loss();
197 register_immediate_alert();
202 void reporter_exit(void)