|
| 1 | +#ifndef BLE_SERVICE_H |
| 2 | +#define BLE_SERVICE_H |
| 3 | + |
| 4 | +#include "host/ble_uuid.h" |
| 5 | + |
| 6 | +#define GATT_DEVICE_INFO_UUID 0x180A |
| 7 | +#define GATT_MANUFACTURER_NAME_UUID 0x2A29 |
| 8 | +#define GATT_MODEL_NUMBER_UUID 0x2A24 |
| 9 | + |
| 10 | +/* CONFIG SERVICE UUID */ |
| 11 | +/* UUID = 2fa1dab8-3eef-40fc-8540-7fc496a10d75 */ |
| 12 | +static const ble_uuid128_t gatt_svr_svc_cfg_uuid |
| 13 | + = BLE_UUID128_INIT(0x75, 0x0d, 0xa1, 0x96, 0xc4, 0x7f, 0x40, 0x85, 0xfc, |
| 14 | + 0x40, 0xef, 0x3e, 0xb8, 0xda, 0xa1, 0x2f); |
| 15 | + |
| 16 | +/* CONFIG DEVICE */ |
| 17 | +/* UUID = d3491796-683b-4b9c-aafb-f51a35459d43 */ |
| 18 | +static const ble_uuid128_t gatt_svr_chr_cfg_device_room_uuid |
| 19 | + = BLE_UUID128_INIT(0x43, 0x9d, 0x45, 0x35, 0x1a, 0xf5, 0xfb, 0xaa, 0x9c, |
| 20 | + 0x4b, 0x3b, 0x68, 0x96, 0x17, 0x49, 0xd3); |
| 21 | + |
| 22 | +/* UUID = 4745e11f-b403-4cfb-83bb-710d46897875 */ |
| 23 | +static const ble_uuid128_t gatt_svr_chr_cfg_device_id_uuid |
| 24 | + = BLE_UUID128_INIT(0x75, 0x78, 0x89, 0x46, 0x0d, 0x71, 0xbb, 0x83, 0xfb, |
| 25 | + 0x4c, 0x03, 0xb4, 0x1f, 0xe1, 0x45, 0x47); |
| 26 | + |
| 27 | +/* CONFIG OTA */ |
| 28 | +/* UUID = 2f44b103-444c-48f5-bf60-91b81dfa0a25 */ |
| 29 | +static const ble_uuid128_t gatt_svr_chr_cfg_ota_host_uuid |
| 30 | + = BLE_UUID128_INIT(0x25, 0x0a, 0xfa, 0x1d, 0xb8, 0x91, 0x60, 0xbf, 0xf5, |
| 31 | + 0x48, 0x4c, 0x44, 0x03, 0xb1, 0x44, 0x2f); |
| 32 | + |
| 33 | +/* UUID = 4b95d245-db08-4c56-98f9-738faa8cfbb6 */ |
| 34 | +static const ble_uuid128_t gatt_svr_chr_cfg_ota_filename_uuid |
| 35 | + = BLE_UUID128_INIT(0xb6, 0xfb, 0x8c, 0xaa, 0x8f, 0x73, 0xf9, 0x98, 0x56, |
| 36 | + 0x4c, 0x08, 0xdb, 0x45, 0xd2, 0x95, 0x4b); |
| 37 | + |
| 38 | +/* UUID = 1c93dce2-3796-4027-9f55-6d251c41dd34 */ |
| 39 | +static const ble_uuid128_t gatt_svr_chr_cfg_ota_server_username_uuid |
| 40 | + = BLE_UUID128_INIT(0x34, 0xdd, 0x41, 0x1c, 0x25, 0x6d, 0x55, 0x9f, 0x27, |
| 41 | + 0x40, 0x96, 0x37, 0xe2, 0xdc, 0x93, 0x1c); |
| 42 | + |
| 43 | +/* UUID = 0e837309-5336-45a3-9b69-d0f7134f30ff */ |
| 44 | +static const ble_uuid128_t gatt_svr_chr_cfg_ota_server_password_uuid |
| 45 | + = BLE_UUID128_INIT(0xff, 0x30, 0x4f, 0x13, 0xf7, 0xd0, 0x69, 0x9b, 0xa3, |
| 46 | + 0x45, 0x36, 0x53, 0x09, 0x73, 0x83, 0x0e); |
| 47 | + |
| 48 | +/* CONFIG WiFi */ |
| 49 | +/* UUID = 8ca0bf1d-bb5d-4a66-9191-341fd805e288 */ |
| 50 | +static const ble_uuid128_t gatt_svr_chr_cfg_wifi_ssid_uuid |
| 51 | + = BLE_UUID128_INIT(0x88, 0xe2, 0x05, 0xd8, 0x1f, 0x34, 0x91, 0x91, 0x66, |
| 52 | + 0x4a, 0x5d, 0xbb, 0x1d, 0xbf, 0xa0, 0x8c); |
| 53 | + |
| 54 | +/* UUID = fa41c195-ae99-422e-8f1f-0730702b3fc5 */ |
| 55 | +static const ble_uuid128_t gatt_svr_chr_cfg_wifi_password_uuid |
| 56 | + = BLE_UUID128_INIT(0xc5, 0x3f, 0x2b, 0x70, 0x30, 0x07, 0x1f, 0x8f, 0x2e, |
| 57 | + 0x42, 0x99, 0xae, 0x95, 0xc1, 0x41, 0xfa); |
| 58 | + |
| 59 | +/* CONFIG MQTT */ |
| 60 | +/* UUID = 69150609-18f8-4523-a41f-6d9a01d2e08d */ |
| 61 | +static const ble_uuid128_t gatt_svr_chr_cfg_mqtt_user_uuid |
| 62 | + = BLE_UUID128_INIT(0x8d, 0xe0, 0xd2, 0x01, 0x9a, 0x6d, 0x1f, 0xa4, 0x23, |
| 63 | + 0x45, 0xf8, 0x18, 0x09, 0x06, 0x15, 0x69); |
| 64 | + |
| 65 | +/* UUID = 8bebec77-ea21-4c14-9d64-dbec1fd5267c */ |
| 66 | +static const ble_uuid128_t gatt_svr_chr_cfg_mqtt_password_uuid |
| 67 | + = BLE_UUID128_INIT(0x7c, 0x26, 0xd5, 0x1f, 0xec, 0xdb, 0x64, 0x9d, 0x14, |
| 68 | + 0x4c, 0x21, 0xea, 0x77, 0xec, 0xeb, 0x8b); |
| 69 | + |
| 70 | +/* UUID = e3b150fb-90a2-4cd3-80c5-b1189e110ef1 */ |
| 71 | +static const ble_uuid128_t gatt_svr_chr_cfg_mqtt_server_ip_uuid |
| 72 | + = BLE_UUID128_INIT(0xf1, 0x0e, 0x11, 0x9e, 0x18, 0xb1, 0xc5, 0x80, 0xd3, |
| 73 | + 0x4c, 0xa2, 0x90, 0xfb, 0x50, 0xb1, 0xe3); |
| 74 | + |
| 75 | +/* UUID = 4eeff953-0f5e-43ee-b1be-1783a8190b0d */ |
| 76 | +static const ble_uuid128_t gatt_svr_chr_cfg_mqtt_server_port_uuid |
| 77 | + = BLE_UUID128_INIT(0x0d, 0x0b, 0x19, 0xa8, 0x83, 0x17, 0xbe, 0xb1, 0xee, |
| 78 | + 0x43, 0x5e, 0x0f, 0x53, 0xf9, 0xef, 0x4e); |
| 79 | + |
| 80 | +/* CONFIG SENSOR */ |
| 81 | +/* UUID = 68011c92-854a-4f2c-a94c-5ee37dc607c3 */ |
| 82 | +static const ble_uuid128_t gatt_svr_chr_cfg_sensor_poll_interval_ms_uuid |
| 83 | + = BLE_UUID128_INIT(0xc3, 0x07, 0xc6, 0x7d, 0xe3, 0x5e, 0x4c, 0xa9, 0x2c, |
| 84 | + 0x4f, 0x4a, 0x85, 0x92, 0x1c, 0x01, 0x68); |
| 85 | + |
| 86 | +/* RESTART */ |
| 87 | +/* UUID = 890f7b6f-cecc-4e3e-ade2-5f2907867f4b */ |
| 88 | +static const ble_uuid128_t gatt_svr_chr_cfg_restart_uuid |
| 89 | + = BLE_UUID128_INIT(0x4b, 0x7f, 0x86, 0x07, 0x29, 0x5f, 0xe2, 0xad, 0x3e, |
| 90 | + 0x4e, 0xcc, 0xce, 0x6f, 0x7b, 0x0f, 0x89); |
| 91 | + |
| 92 | +static int gatt_svr_chr_access_device_info_manufacturer( |
| 93 | + uint16_t conn_handle, uint16_t attr_handle, |
| 94 | + struct ble_gatt_access_ctxt *ctxt, void *arg); |
| 95 | + |
| 96 | +static int gatt_svr_chr_access_device_info_model( |
| 97 | + uint16_t conn_handle, uint16_t attr_handle, |
| 98 | + struct ble_gatt_access_ctxt *ctxt, void *arg); |
| 99 | + |
| 100 | +static int gatt_svr_chr_access_rw_demo( |
| 101 | + uint16_t conn_handle, uint16_t attr_handle, |
| 102 | + struct ble_gatt_access_ctxt *ctxt, void *arg); |
| 103 | + |
| 104 | +/* define several bluetooth services for our device */ |
| 105 | +static const struct ble_gatt_svc_def gatt_svr_svcs[] = { |
| 106 | + /* |
| 107 | + * access_cb defines a callback for read and write access events on |
| 108 | + * given characteristics |
| 109 | + */ |
| 110 | + { |
| 111 | + /* Service: Device Information */ |
| 112 | + .type = BLE_GATT_SVC_TYPE_PRIMARY, |
| 113 | + .uuid = BLE_UUID16_DECLARE(GATT_DEVICE_INFO_UUID), |
| 114 | + .characteristics = (struct ble_gatt_chr_def[]) { { |
| 115 | + /* Characteristic: * Manufacturer name */ |
| 116 | + .uuid = BLE_UUID16_DECLARE(GATT_MANUFACTURER_NAME_UUID), |
| 117 | + .access_cb = gatt_svr_chr_access_device_info_manufacturer, |
| 118 | + .flags = BLE_GATT_CHR_F_READ, |
| 119 | + }, { |
| 120 | + /* Characteristic: Model number string */ |
| 121 | + .uuid = BLE_UUID16_DECLARE(GATT_MODEL_NUMBER_UUID), |
| 122 | + .access_cb = gatt_svr_chr_access_device_info_model, |
| 123 | + .flags = BLE_GATT_CHR_F_READ, |
| 124 | + }, { |
| 125 | + 0, /* No more characteristics in this service */ |
| 126 | + }, } |
| 127 | + }, |
| 128 | + { |
| 129 | + /* Service: Config */ |
| 130 | + .type = BLE_GATT_SVC_TYPE_PRIMARY, |
| 131 | + .uuid = (ble_uuid_t*) &gatt_svr_svc_cfg_uuid.u, |
| 132 | + .characteristics = (struct ble_gatt_chr_def[]) { { |
| 133 | + /* Characteristic: Config device room */ |
| 134 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_device_room_uuid.u, |
| 135 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 136 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 137 | + },{ |
| 138 | + /* Characteristic: Config device id */ |
| 139 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_device_id_uuid.u, |
| 140 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 141 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 142 | + },{ |
| 143 | + /* Characteristic: Config ota host */ |
| 144 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_ota_host_uuid.u, |
| 145 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 146 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 147 | + },{ |
| 148 | + /* Characteristic: Config ota filename */ |
| 149 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_ota_filename_uuid.u, |
| 150 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 151 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 152 | + },{ |
| 153 | + /* Characteristic: Config ota server username */ |
| 154 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_ota_server_username_uuid.u, |
| 155 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 156 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 157 | + },{ |
| 158 | + /* Characteristic: Config ota server password */ |
| 159 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_ota_server_password_uuid.u, |
| 160 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 161 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 162 | + },{ |
| 163 | + /* Characteristic: Config wifi ssid */ |
| 164 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_wifi_ssid_uuid.u, |
| 165 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 166 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 167 | + },{ |
| 168 | + /* Characteristic: Config wifi password */ |
| 169 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_wifi_password_uuid.u, |
| 170 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 171 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 172 | + },{ |
| 173 | + /* Characteristic: Config mqtt user */ |
| 174 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_mqtt_user_uuid.u, |
| 175 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 176 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 177 | + },{ |
| 178 | + /* Characteristic: Config mqtt password */ |
| 179 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_mqtt_password_uuid.u, |
| 180 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 181 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 182 | + },{ |
| 183 | + /* Characteristic: Config mqtt server ip */ |
| 184 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_mqtt_server_ip_uuid.u, |
| 185 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 186 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 187 | + },{ |
| 188 | + /* Characteristic: Config mqtt server port */ |
| 189 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_mqtt_server_port_uuid.u, |
| 190 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 191 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 192 | + },{ |
| 193 | + /* Characteristic: Config sensor poll interval ms */ |
| 194 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_sensor_poll_interval_ms_uuid.u, |
| 195 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 196 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 197 | + },{ |
| 198 | + /* Characteristic: Config save and restart */ |
| 199 | + .uuid = (ble_uuid_t*) &gatt_svr_chr_cfg_restart_uuid.u, |
| 200 | + .access_cb = gatt_svr_chr_access_rw_demo, |
| 201 | + .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE, |
| 202 | + },{ |
| 203 | + 0, /* No more characteristics in this service */ |
| 204 | + }, } |
| 205 | + }, |
| 206 | + { |
| 207 | + 0, /* No more services */ |
| 208 | + }, |
| 209 | +}; |
| 210 | + |
| 211 | +#endif /*BLE_SERVICE_H*/ |
0 commit comments