Skip to content

Commit b36858d

Browse files
committed
Fix advertisement
1 parent 3177973 commit b36858d

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

devices/ble_hci/common-hal/_bleio/Adapter.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
118118
SECURITY_MODE_NO_ACCESS,
119119
248, // max length, from Bluetooth spec
120120
false, // not fixed length
121-
&generic_name_bufinfo
121+
&generic_name_bufinfo,
122+
NULL
122123
);
123124

124125
uint16_t zero_16 = 0;
@@ -140,7 +141,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
140141
SECURITY_MODE_NO_ACCESS,
141142
2, // max length, from Bluetooth spec
142143
true, // fixed length
143-
&zero_16_value
144+
&zero_16_value,
145+
NULL
144146
);
145147

146148
// Generic Attribute Service setup.
@@ -176,7 +178,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
176178
SECURITY_MODE_NO_ACCESS,
177179
4, // max length, from Bluetooth spec
178180
true, // fixed length
179-
&zero_32_value
181+
&zero_32_value,
182+
NULL
180183
);
181184
}
182185

devices/ble_hci/common-hal/_bleio/Characteristic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define CCCD_INDICATE 0x2
4242

4343

44-
void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service, uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm, mp_int_t max_length, bool fixed_length, mp_buffer_info_t *initial_value_bufinfo) {
44+
void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service, uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm, mp_int_t max_length, bool fixed_length, mp_buffer_info_t *initial_value_bufinfo, const char *user_description) {
4545
self->service = service;
4646
self->uuid = uuid;
4747
self->decl_handle = BLE_GATT_HANDLE_INVALID;
@@ -66,7 +66,7 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
6666
if (service->is_remote) {
6767
self->handle = handle;
6868
} else {
69-
common_hal_bleio_service_add_characteristic(self->service, self, initial_value_bufinfo);
69+
common_hal_bleio_service_add_characteristic(self->service, self, initial_value_bufinfo, user_description);
7070
}
7171
}
7272

devices/ble_hci/common-hal/_bleio/Service.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) {
8484

8585
void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
8686
bleio_characteristic_obj_t *characteristic,
87-
mp_buffer_info_t *initial_value_bufinfo) {
87+
mp_buffer_info_t *initial_value_bufinfo,
88+
const char *user_description) {
8889

8990
if (self->handle != common_hal_bleio_adapter_obj.last_added_service_handle) {
9091
mp_raise_bleio_BluetoothError(

devices/ble_hci/common-hal/_bleio/__init__.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include "shared-bindings/_bleio/Descriptor.h"
3737
#include "shared-bindings/_bleio/Service.h"
3838
#include "shared-bindings/_bleio/UUID.h"
39-
#include "supervisor/shared/bluetooth.h"
39+
#include "supervisor/shared/bluetooth/bluetooth.h"
4040

4141
// UUID shared by all cccd's.
4242
bleio_uuid_obj_t cccd_uuid;

supervisor/shared/bluetooth/bluetooth.c

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#include "shared-bindings/microcontroller/ResetReason.h"
3838
#include "shared-module/storage/__init__.h"
3939

40-
#include "bluetooth/ble_drv.h"
41-
4240
#include "common-hal/_bleio/__init__.h"
4341

4442
#include "supervisor/shared/status_leds.h"
@@ -48,10 +46,12 @@
4846

4947
#if CIRCUITPY_BLE_FILE_SERVICE
5048
#include "supervisor/shared/bluetooth/file_transfer.h"
49+
#include "bluetooth/ble_drv.h"
5150
#endif
5251

5352
#if CIRCUITPY_SERIAL_BLE
5453
#include "supervisor/shared/bluetooth/serial.h"
54+
#include "bluetooth/ble_drv.h"
5555
#endif
5656

5757
// This standard advertisement advertises the CircuitPython editing service and a CIRCUITPY short name.
@@ -75,18 +75,21 @@ const uint8_t public_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags
7575
const uint8_t private_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags
7676
0x02, 0x0a, 0x00 // 3-5 TX power level 0
7777
};
78-
// This scan response advertises the full CIRCUITPYXXXX device name.
78+
// This scan response advertises the full CIRCPYXXXX device name.
7979
uint8_t circuitpython_scan_response_data[] = {
80-
0x0e, 0x09, 0x43, 0x49, 0x52, 0x43, 0x55, 0x49, 0x54, 0x50, 0x59, 0x00, 0x00, 0x00, 0x00,
80+
0x0a, 0x09, 0x43, 0x49, 0x52, 0x50, 0x59, 0x00, 0x00, 0x00, 0x00,
8181
#if CIRCUITPY_SERIAL_BLE
82-
0x06, 0x10, 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x00, 0x00, 0x40, 0x6e,
82+
0x11, 0x06, 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e,
8383
#endif
8484
};
8585

8686
bool boot_in_discovery_mode = false;
8787
bool advertising = false;
8888

8989
STATIC void supervisor_bluetooth_start_advertising(void) {
90+
// #if !CIRCUITPY_BLE_FILE_SERVICE && !CIRCUITPY_SERIAL_BLE
91+
// return;
92+
// #else
9093
bool is_connected = common_hal_bleio_adapter_get_connected(&common_hal_bleio_adapter_obj);
9194
if (is_connected) {
9295
return;
@@ -95,7 +98,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
9598
#if CIRCUITPY_USB
9699
// Don't advertise when we have USB instead of BLE.
97100
if (!bonded && !boot_in_discovery_mode) {
98-
// mp_printf(&mp_plat_print, "skipping advertising\n");
101+
mp_printf(&mp_plat_print, "skipping advertising\n");
99102
return;
100103
}
101104
#endif
@@ -109,6 +112,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
109112
// Advertise with less power when doing so publicly to reduce who can hear us. This will make it
110113
// harder for someone with bad intentions to pair from a distance.
111114
if (!bonded) {
115+
mp_printf(&mp_plat_print, "public advertising\n");
112116
tx_power = -40;
113117
adv = public_advertising_data;
114118
adv_len = sizeof(public_advertising_data);
@@ -126,6 +130,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
126130
scan_response_len,
127131
tx_power,
128132
NULL);
133+
mp_printf(&mp_plat_print, "advert %d\n", status);
129134
// This may fail if we are already advertising.
130135
advertising = status == NRF_SUCCESS;
131136
}
@@ -139,20 +144,22 @@ void supervisor_bluetooth_init(void) {
139144
if ((reset_state & BLE_DISCOVERY_DATA_GUARD_MASK) == BLE_DISCOVERY_DATA_GUARD) {
140145
ble_mode = (reset_state & ~BLE_DISCOVERY_DATA_GUARD_MASK) >> 8;
141146
}
142-
const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
147+
// const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
143148
boot_in_discovery_mode = false;
144-
if (reset_reason != RESET_REASON_POWER_ON &&
145-
reset_reason != RESET_REASON_RESET_PIN &&
146-
reset_reason != RESET_REASON_UNKNOWN &&
147-
reset_reason != RESET_REASON_SOFTWARE) {
148-
return;
149-
}
149+
// if (reset_reason != RESET_REASON_POWER_ON &&
150+
// reset_reason != RESET_REASON_RESET_PIN &&
151+
// reset_reason != RESET_REASON_UNKNOWN &&
152+
// reset_reason != RESET_REASON_SOFTWARE) {
153+
// return;
154+
// }
150155

151156
if (ble_mode == 0) {
152157
port_set_saved_word(BLE_DISCOVERY_DATA_GUARD | (0x01 << 8));
153158
}
154159
// Wait for a while to allow for reset.
155160

161+
ble_mode = 1;
162+
156163
#ifdef CIRCUITPY_BOOT_BUTTON
157164
digitalio_digitalinout_obj_t boot_button;
158165
common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);

0 commit comments

Comments
 (0)