Fix advertisement
This commit is contained in:
parent
3177973843
commit
b36858daa0
|
@ -118,7 +118,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
|
|||
SECURITY_MODE_NO_ACCESS,
|
||||
248, // max length, from Bluetooth spec
|
||||
false, // not fixed length
|
||||
&generic_name_bufinfo
|
||||
&generic_name_bufinfo,
|
||||
NULL
|
||||
);
|
||||
|
||||
uint16_t zero_16 = 0;
|
||||
|
@ -140,7 +141,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
|
|||
SECURITY_MODE_NO_ACCESS,
|
||||
2, // max length, from Bluetooth spec
|
||||
true, // fixed length
|
||||
&zero_16_value
|
||||
&zero_16_value,
|
||||
NULL
|
||||
);
|
||||
|
||||
// Generic Attribute Service setup.
|
||||
|
@ -176,7 +178,8 @@ STATIC void add_generic_services(bleio_adapter_obj_t *adapter) {
|
|||
SECURITY_MODE_NO_ACCESS,
|
||||
4, // max length, from Bluetooth spec
|
||||
true, // fixed length
|
||||
&zero_32_value
|
||||
&zero_32_value,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#define CCCD_INDICATE 0x2
|
||||
|
||||
|
||||
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) {
|
||||
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) {
|
||||
self->service = service;
|
||||
self->uuid = uuid;
|
||||
self->decl_handle = BLE_GATT_HANDLE_INVALID;
|
||||
|
@ -66,7 +66,7 @@ void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self,
|
|||
if (service->is_remote) {
|
||||
self->handle = handle;
|
||||
} else {
|
||||
common_hal_bleio_service_add_characteristic(self->service, self, initial_value_bufinfo);
|
||||
common_hal_bleio_service_add_characteristic(self->service, self, initial_value_bufinfo, user_description);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,8 @@ bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) {
|
|||
|
||||
void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
|
||||
bleio_characteristic_obj_t *characteristic,
|
||||
mp_buffer_info_t *initial_value_bufinfo) {
|
||||
mp_buffer_info_t *initial_value_bufinfo,
|
||||
const char *user_description) {
|
||||
|
||||
if (self->handle != common_hal_bleio_adapter_obj.last_added_service_handle) {
|
||||
mp_raise_bleio_BluetoothError(
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "shared-bindings/_bleio/Descriptor.h"
|
||||
#include "shared-bindings/_bleio/Service.h"
|
||||
#include "shared-bindings/_bleio/UUID.h"
|
||||
#include "supervisor/shared/bluetooth.h"
|
||||
#include "supervisor/shared/bluetooth/bluetooth.h"
|
||||
|
||||
// UUID shared by all cccd's.
|
||||
bleio_uuid_obj_t cccd_uuid;
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
#include "shared-bindings/microcontroller/ResetReason.h"
|
||||
#include "shared-module/storage/__init__.h"
|
||||
|
||||
#include "bluetooth/ble_drv.h"
|
||||
|
||||
#include "common-hal/_bleio/__init__.h"
|
||||
|
||||
#include "supervisor/shared/status_leds.h"
|
||||
|
@ -48,10 +46,12 @@
|
|||
|
||||
#if CIRCUITPY_BLE_FILE_SERVICE
|
||||
#include "supervisor/shared/bluetooth/file_transfer.h"
|
||||
#include "bluetooth/ble_drv.h"
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_SERIAL_BLE
|
||||
#include "supervisor/shared/bluetooth/serial.h"
|
||||
#include "bluetooth/ble_drv.h"
|
||||
#endif
|
||||
|
||||
// This standard advertisement advertises the CircuitPython editing service and a CIRCUITPY short name.
|
||||
|
@ -75,11 +75,11 @@ const uint8_t public_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags
|
|||
const uint8_t private_advertising_data[] = { 0x02, 0x01, 0x06, // 0-2 Flags
|
||||
0x02, 0x0a, 0x00 // 3-5 TX power level 0
|
||||
};
|
||||
// This scan response advertises the full CIRCUITPYXXXX device name.
|
||||
// This scan response advertises the full CIRCPYXXXX device name.
|
||||
uint8_t circuitpython_scan_response_data[] = {
|
||||
0x0e, 0x09, 0x43, 0x49, 0x52, 0x43, 0x55, 0x49, 0x54, 0x50, 0x59, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0a, 0x09, 0x43, 0x49, 0x52, 0x50, 0x59, 0x00, 0x00, 0x00, 0x00,
|
||||
#if CIRCUITPY_SERIAL_BLE
|
||||
0x06, 0x10, 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x00, 0x00, 0x40, 0x6e,
|
||||
0x11, 0x06, 0x9e, 0xca, 0xdc, 0x24, 0x0e, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x01, 0x00, 0x40, 0x6e,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -87,6 +87,9 @@ bool boot_in_discovery_mode = false;
|
|||
bool advertising = false;
|
||||
|
||||
STATIC void supervisor_bluetooth_start_advertising(void) {
|
||||
// #if !CIRCUITPY_BLE_FILE_SERVICE && !CIRCUITPY_SERIAL_BLE
|
||||
// return;
|
||||
// #else
|
||||
bool is_connected = common_hal_bleio_adapter_get_connected(&common_hal_bleio_adapter_obj);
|
||||
if (is_connected) {
|
||||
return;
|
||||
|
@ -95,7 +98,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
|
|||
#if CIRCUITPY_USB
|
||||
// Don't advertise when we have USB instead of BLE.
|
||||
if (!bonded && !boot_in_discovery_mode) {
|
||||
// mp_printf(&mp_plat_print, "skipping advertising\n");
|
||||
mp_printf(&mp_plat_print, "skipping advertising\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -109,6 +112,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
|
|||
// Advertise with less power when doing so publicly to reduce who can hear us. This will make it
|
||||
// harder for someone with bad intentions to pair from a distance.
|
||||
if (!bonded) {
|
||||
mp_printf(&mp_plat_print, "public advertising\n");
|
||||
tx_power = -40;
|
||||
adv = public_advertising_data;
|
||||
adv_len = sizeof(public_advertising_data);
|
||||
|
@ -126,6 +130,7 @@ STATIC void supervisor_bluetooth_start_advertising(void) {
|
|||
scan_response_len,
|
||||
tx_power,
|
||||
NULL);
|
||||
mp_printf(&mp_plat_print, "advert %d\n", status);
|
||||
// This may fail if we are already advertising.
|
||||
advertising = status == NRF_SUCCESS;
|
||||
}
|
||||
|
@ -139,20 +144,22 @@ void supervisor_bluetooth_init(void) {
|
|||
if ((reset_state & BLE_DISCOVERY_DATA_GUARD_MASK) == BLE_DISCOVERY_DATA_GUARD) {
|
||||
ble_mode = (reset_state & ~BLE_DISCOVERY_DATA_GUARD_MASK) >> 8;
|
||||
}
|
||||
const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
|
||||
// const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
|
||||
boot_in_discovery_mode = false;
|
||||
if (reset_reason != RESET_REASON_POWER_ON &&
|
||||
reset_reason != RESET_REASON_RESET_PIN &&
|
||||
reset_reason != RESET_REASON_UNKNOWN &&
|
||||
reset_reason != RESET_REASON_SOFTWARE) {
|
||||
return;
|
||||
}
|
||||
// if (reset_reason != RESET_REASON_POWER_ON &&
|
||||
// reset_reason != RESET_REASON_RESET_PIN &&
|
||||
// reset_reason != RESET_REASON_UNKNOWN &&
|
||||
// reset_reason != RESET_REASON_SOFTWARE) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (ble_mode == 0) {
|
||||
port_set_saved_word(BLE_DISCOVERY_DATA_GUARD | (0x01 << 8));
|
||||
}
|
||||
// Wait for a while to allow for reset.
|
||||
|
||||
ble_mode = 1;
|
||||
|
||||
#ifdef CIRCUITPY_BOOT_BUTTON
|
||||
digitalio_digitalinout_obj_t boot_button;
|
||||
common_hal_digitalio_digitalinout_construct(&boot_button, CIRCUITPY_BOOT_BUTTON);
|
||||
|
|
Loading…
Reference in New Issue