mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
Merge branch 'release/v5.4' into 'feat/add_cte_iq_report_example_v5.4'
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
# The following lines of boilerplate have to be in your project's
|
||||
# CMakeLists in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
|
||||
idf_build_set_property(MINIMAL_BUILD ON)
|
||||
project(ble_ancs)
|
||||
@@ -0,0 +1,65 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
|
||||
|
||||
# ESP-IDF NimBLE ANCS Example
|
||||
|
||||
The purpose of the Apple Notification Center Service (ANCS) is to give Bluetooth accessories (that connect to iOS devices through a Bluetooth low-energy link) a simple and convenient way to access many kinds of notifications that are generated on iOS devices.
|
||||
|
||||
## How to Use Example
|
||||
|
||||
Before project configuration and build, be sure to set the correct chip target using:
|
||||
|
||||
```bash
|
||||
idf.py set-target <chip_name>
|
||||
```
|
||||
|
||||
The Apple Notification Center Service is a primary service whose service UUID is:
|
||||
|
||||
`7905F431-B5CE-4E99-A40F-4B1E122D00D0`
|
||||
|
||||
Only one instance of the ANCS may be present on an NP. Due to the nature of iOS, the ANCS is not guaranteed to always be present. As a result, the NC should look for and subscribe to the Service Changed characteristic of the GATT service in order to monitor for the potential publishing and unpublishing of the ANCS at any time.
|
||||
|
||||
In its basic form, the ANCS exposes three characteristics:
|
||||
Notification Source: UUID `9FBF120D-6301-42D9-8C58-25E699A21DBD` (notifiable)
|
||||
Control Point: UUID `69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9` (writeable with response)
|
||||
Data Source: UUID `22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB` (notifiable)
|
||||
|
||||
All these characteristics require authorization for access.
|
||||
|
||||
### Hardware Required
|
||||
|
||||
* A development board with ESP32/ESP32-C3/ESP32-H2/ESP32-C2/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
|
||||
* A USB cable for power supply and programming
|
||||
|
||||
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
|
||||
|
||||
### Build and Flash
|
||||
|
||||
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
|
||||
|
||||
(To exit the serial monitor, type ``Ctrl-]``.)
|
||||
|
||||
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
|
||||
|
||||
## Example Output
|
||||
|
||||
```
|
||||
I (466) NimBLE ANCS: BLE Host Task Started
|
||||
I (466) NimBLE: GAP procedure initiated: stop advertising.
|
||||
|
||||
I (476) NimBLE: Device Address:
|
||||
I (476) NimBLE: 48:27:e2:e9:0e:a6
|
||||
I (476) NimBLE:
|
||||
|
||||
I (476) NimBLE: GAP procedure initiated: advertise;
|
||||
I (476) NimBLE: disc_mode=2
|
||||
I (476) NimBLE: adv_channel_map=0 own_addr_type=0 adv_filter_policy=0 adv_itvl_min=0 adv_itvl_max=0
|
||||
I (486) NimBLE:
|
||||
|
||||
I (496) uart: queue free spaces: 8
|
||||
I (496) main_task: Returned from app_main()
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
@@ -0,0 +1,5 @@
|
||||
set(srcs "main.c"
|
||||
"ble_ancs.c")
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,14 @@
|
||||
menu "Example Configuration"
|
||||
|
||||
config EXAMPLE_EXTENDED_ADV
|
||||
bool
|
||||
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
|
||||
default y if SOC_ESP_NIMBLE_CONTROLLER
|
||||
select BT_NIMBLE_EXT_ADV
|
||||
prompt "Enable Extended Adv"
|
||||
help
|
||||
Use this option to enable extended advertising in the example.
|
||||
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
|
||||
also disabled from Nimble stack menuconfig
|
||||
|
||||
endmenu
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "esp_log.h"
|
||||
#include "ble_ancs.h"
|
||||
|
||||
#define NimBLE_ANCS_TAG "NimBLE_ANCS"
|
||||
|
||||
/*
|
||||
| EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) |
|
||||
|
||||
A GATT notification delivered through the Notification Source characteristic contains the following information:
|
||||
* EventID: This field informs the accessory whether the given iOS notification was added, modified, or removed. The enumerated values for this field are defined
|
||||
in EventID Values.
|
||||
* EventFlags: A bitmask whose set bits inform an NC of specificities with the iOS notification. For example, if an iOS notification is considered “important”,
|
||||
the NC may want to display a more aggressive user interface (UI) to make sure the user is properly alerted. The enumerated bits for this field
|
||||
are defined in EventFlags.
|
||||
* CategoryID: A numerical value providing a category in which the iOS notification can be classified. The NP will make a best effort to provide an accurate category
|
||||
for each iOS notification. The enumerated values for this field are defined in CategoryID Values.
|
||||
* CategoryCount: The current number of active iOS notifications in the given category. For example, if two unread emails are sitting in a user’s email inbox, and a new
|
||||
email is pushed to the user’s iOS device, the value of CategoryCount is 3.
|
||||
* NotificationUID: A 32-bit numerical value that is the unique identifier (UID) for the iOS notification. This value can be used as a handle in commands sent to the
|
||||
Control Point characteristic to interact with the iOS notification.
|
||||
*/
|
||||
|
||||
char *EventID_to_String(uint8_t EventID)
|
||||
{
|
||||
char *str = NULL;
|
||||
switch (EventID)
|
||||
{
|
||||
case EventIDNotificationAdded:
|
||||
str = "New message";
|
||||
break;
|
||||
case EventIDNotificationModified:
|
||||
str = "Modified message";
|
||||
break;
|
||||
case EventIDNotificationRemoved:
|
||||
str = "Removed message";
|
||||
break;
|
||||
default:
|
||||
str = "unknown EventID";
|
||||
break;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
char *CategoryID_to_String(uint8_t CategoryID)
|
||||
{
|
||||
char *Cidstr = NULL;
|
||||
switch(CategoryID) {
|
||||
case CategoryIDOther:
|
||||
Cidstr = "Other";
|
||||
break;
|
||||
case CategoryIDIncomingCall:
|
||||
Cidstr = "IncomingCall";
|
||||
break;
|
||||
case CategoryIDMissedCall:
|
||||
Cidstr = "MissedCall";
|
||||
break;
|
||||
case CategoryIDVoicemail:
|
||||
Cidstr = "Voicemail";
|
||||
break;
|
||||
case CategoryIDSocial:
|
||||
Cidstr = "Social";
|
||||
break;
|
||||
case CategoryIDSchedule:
|
||||
Cidstr = "Schedule";
|
||||
break;
|
||||
case CategoryIDEmail:
|
||||
Cidstr = "Email";
|
||||
break;
|
||||
case CategoryIDNews:
|
||||
Cidstr = "News";
|
||||
break;
|
||||
case CategoryIDHealthAndFitness:
|
||||
Cidstr = "HealthAndFitness";
|
||||
break;
|
||||
case CategoryIDBusinessAndFinance:
|
||||
Cidstr = "BusinessAndFinance";
|
||||
break;
|
||||
case CategoryIDLocation:
|
||||
Cidstr = "Location";
|
||||
break;
|
||||
case CategoryIDEntertainment:
|
||||
Cidstr = "Entertainment";
|
||||
break;
|
||||
default:
|
||||
Cidstr = "Unknown CategoryID";
|
||||
break;
|
||||
}
|
||||
return Cidstr;
|
||||
}
|
||||
|
||||
/*
|
||||
| EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) |
|
||||
*/
|
||||
|
||||
void ble_receive_apple_notification_source(uint8_t *message, uint16_t message_len)
|
||||
{
|
||||
if (!message || message_len < 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t EventID = message[0];
|
||||
char *EventIDS = EventID_to_String(EventID);
|
||||
uint8_t EventFlags = message[1];
|
||||
uint8_t CategoryID = message[2];
|
||||
char *Cidstr = CategoryID_to_String(CategoryID);
|
||||
uint8_t CategoryCount = message[3];
|
||||
uint32_t NotificationUID = (message[4]) | (message[5]<< 8) | (message[6]<< 16) | (message[7] << 24);
|
||||
ESP_LOGI(NimBLE_ANCS_TAG, "EventID:%s EventFlags:0x%x CategoryID:%s CategoryCount:%d NotificationUID:%" PRIu32, EventIDS, EventFlags, Cidstr, CategoryCount, NotificationUID);
|
||||
}
|
||||
|
||||
void ble_receive_apple_data_source(uint8_t *message, uint16_t message_len)
|
||||
{
|
||||
if (!message || message_len == 0) {
|
||||
return;
|
||||
}
|
||||
uint8_t Command_id = message[0];
|
||||
switch (Command_id)
|
||||
{
|
||||
case CommandIDGetNotificationAttributes: {
|
||||
uint32_t NotificationUID = (message[1]) | (message[2]<< 8) | (message[3]<< 16) | (message[4] << 24);
|
||||
uint32_t remian_attr_len = message_len - 5;
|
||||
uint8_t *attrs = &message[5];
|
||||
ESP_LOGI(NimBLE_ANCS_TAG, "recevice Notification Attributes response Command_id %d NotificationUID %" PRIu32, Command_id, NotificationUID);
|
||||
while(remian_attr_len > 0) {
|
||||
uint8_t AttributeID = attrs[0];
|
||||
uint16_t len = attrs[1] | (attrs[2] << 8);
|
||||
if(len > (remian_attr_len -3)) {
|
||||
ESP_LOGE(NimBLE_ANCS_TAG, "data error");
|
||||
break;
|
||||
}
|
||||
switch (AttributeID)
|
||||
{
|
||||
case NotificationAttributeIDAppIdentifier:
|
||||
ESP_LOG_BUFFER_CHAR("Identifier", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDTitle:
|
||||
ESP_LOG_BUFFER_CHAR("Title", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDSubtitle:
|
||||
ESP_LOG_BUFFER_CHAR("Subtitle", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDMessage:
|
||||
ESP_LOG_BUFFER_CHAR("Message", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDMessageSize:
|
||||
ESP_LOG_BUFFER_CHAR("MessageSize", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDDate:
|
||||
//yyyyMMdd'T'HHmmSS
|
||||
ESP_LOG_BUFFER_CHAR("Date", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDPositiveActionLabel:
|
||||
ESP_LOG_BUFFER_HEX("PActionLabel", &attrs[3], len);
|
||||
break;
|
||||
case NotificationAttributeIDNegativeActionLabel:
|
||||
ESP_LOG_BUFFER_HEX("NActionLabel", &attrs[3], len);
|
||||
break;
|
||||
default:
|
||||
ESP_LOG_BUFFER_HEX("unknownAttributeID", &attrs[3], len);
|
||||
break;
|
||||
}
|
||||
|
||||
attrs += (1 + 2 + len);
|
||||
remian_attr_len -= (1 + 2 + len);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CommandIDGetAppAttributes:
|
||||
ESP_LOGI(NimBLE_ANCS_TAG, "recevice APP Attributes response");
|
||||
break;
|
||||
case CommandIDPerformNotificationAction:
|
||||
ESP_LOGI(NimBLE_ANCS_TAG, "recevice Perform Notification Action");
|
||||
break;
|
||||
default:
|
||||
ESP_LOGI(NimBLE_ANCS_TAG, "unknown Command ID");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
char *Errcode_to_String(uint16_t status)
|
||||
{
|
||||
char *Errstr = NULL;
|
||||
switch (status) {
|
||||
case Unknown_command:
|
||||
Errstr = "Unknown_command";
|
||||
break;
|
||||
case Invalid_command:
|
||||
Errstr = "Invalid_command";
|
||||
break;
|
||||
case Invalid_parameter:
|
||||
Errstr = "Invalid_parameter";
|
||||
break;
|
||||
case Action_failed:
|
||||
Errstr = "Action_failed";
|
||||
break;
|
||||
default:
|
||||
Errstr = "unknown_failed";
|
||||
break;
|
||||
}
|
||||
return Errstr;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
//EventID values
|
||||
typedef enum {
|
||||
EventIDNotificationAdded = 0,
|
||||
EventIDNotificationModified = 1,
|
||||
EventIDNotificationRemoved = 2,
|
||||
//Reserved EventID values = 3–255
|
||||
} ble_ancs_EventID;
|
||||
|
||||
//EventFlags
|
||||
typedef enum {
|
||||
EventFlagSilent = (1 << 0),
|
||||
EventFlagImportant = (1 << 1),
|
||||
EventFlagPreExisting = (1 << 2),
|
||||
EventFlagPositiveAction = (1 << 3),
|
||||
EventFlagNegativeAction = (1 << 4),
|
||||
//Reserved EventFlags = (1 << 5)–(1 << 7
|
||||
}ble_ancs_EventFlags;
|
||||
|
||||
// CategoryID values
|
||||
typedef enum {
|
||||
CategoryIDOther = 0,
|
||||
CategoryIDIncomingCall = 1,
|
||||
CategoryIDMissedCall = 2,
|
||||
CategoryIDVoicemail = 3,
|
||||
CategoryIDSocial = 4,
|
||||
CategoryIDSchedule = 5,
|
||||
CategoryIDEmail = 6,
|
||||
CategoryIDNews = 7,
|
||||
CategoryIDHealthAndFitness = 8,
|
||||
CategoryIDBusinessAndFinance = 9,
|
||||
CategoryIDLocation = 10,
|
||||
CategoryIDEntertainment = 11,
|
||||
//Reserved CategoryID values = 12–255
|
||||
} ble_ancs_CategoryID;
|
||||
|
||||
//CommandID values
|
||||
typedef enum {
|
||||
CommandIDGetNotificationAttributes = 0,
|
||||
CommandIDGetAppAttributes = 1,
|
||||
CommandIDPerformNotificationAction = 2,
|
||||
//Reserved CommandID values = 3–255
|
||||
} ble_ancs_CommandID;
|
||||
|
||||
//NotificationAttributeID
|
||||
typedef enum {
|
||||
NotificationAttributeIDAppIdentifier = 0,
|
||||
NotificationAttributeIDTitle = 1, //(Needs to be followed by a 2-bytes max length parameter)
|
||||
NotificationAttributeIDSubtitle = 2, //(Needs to be followed by a 2-bytes max length parameter)
|
||||
NotificationAttributeIDMessage = 3, //(Needs to be followed by a 2-bytes max length parameter)
|
||||
NotificationAttributeIDMessageSize = 4,
|
||||
NotificationAttributeIDDate = 5,
|
||||
NotificationAttributeIDPositiveActionLabel = 6,
|
||||
NotificationAttributeIDNegativeActionLabel = 7,
|
||||
//Reserved NotificationAttributeID values = 8–255
|
||||
} ble_ancs_NotificationAttributeID;
|
||||
|
||||
/*
|
||||
Note: The format of the NotificationAttributeIDMessageSize constant is a string that represents the integral value
|
||||
of the message size. The format of the NotificationAttributeIDDate constant is a string that uses the Unicode Technical
|
||||
Standard (UTS) #35 date format pattern yyyyMMdd'T'HHmmSS. The format of all the other constants in Table 3-5 are UTF-8
|
||||
strings.
|
||||
*/
|
||||
|
||||
//ActionID values
|
||||
typedef enum {
|
||||
ActionIDPositive = 0,
|
||||
ActionIDNegative = 1,
|
||||
//Reserved ActionID values = 2–255
|
||||
} ble_ActionID;
|
||||
|
||||
//AppAttributeID Values
|
||||
typedef enum {
|
||||
AppAttributeIDDisplayName = 0,
|
||||
//Reserved AppAttributeID values = 1–255
|
||||
} ble_AppAttributeID;
|
||||
|
||||
typedef struct {
|
||||
uint8_t noti_attribute_id;
|
||||
uint16_t attribute_len;
|
||||
} ble_noti_attr_list_t;
|
||||
|
||||
typedef enum {
|
||||
Unknown_command = (0xA0), //The commandID was not recognized by the NP.
|
||||
Invalid_command = (0xA1), //The command was improperly formatted.
|
||||
Invalid_parameter = (0xA2), // One of the parameters (for example, the NotificationUID) does not refer to an existing object on the NP.
|
||||
Action_failed = (0xA3), //The action was not performed
|
||||
} ble_ancs_error_code;
|
||||
|
||||
typedef enum {
|
||||
attr_appidentifier_index = 0, //The commandID was not recognized by the NP.
|
||||
attr_title_index,
|
||||
attr_subtitle_index,
|
||||
attr_message_index,
|
||||
attr_messagesize_index,
|
||||
attr_date_index,
|
||||
attr_positiveactionlabel_index,
|
||||
attr_negativeactionlabel_index,
|
||||
} ble_ancs_attr_index;
|
||||
|
||||
#define ESP_NOTIFICATIONUID_LEN 4
|
||||
|
||||
|
||||
char *EventID_to_String(uint8_t EventID);
|
||||
char *CategoryID_to_String(uint8_t CategoryID);
|
||||
void ble_receive_apple_notification_source(uint8_t *message, uint16_t message_len);
|
||||
void ble_receive_apple_data_source(uint8_t *message, uint16_t message_len);
|
||||
char *Errcode_to_String(uint16_t status);
|
||||
@@ -0,0 +1,3 @@
|
||||
dependencies:
|
||||
nimble_peripheral_utils:
|
||||
path: ${IDF_PATH}/examples/bluetooth/nimble/common/nimble_peripheral_utils
|
||||
@@ -0,0 +1,771 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
/* BLE */
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "console/console.h"
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "esp_peripheral.h"
|
||||
#include "ble_ancs.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
uint16_t notification_source_handle;
|
||||
uint16_t data_source_handle;
|
||||
uint16_t control_point_handle;
|
||||
uint16_t svc_e_handle;
|
||||
|
||||
static void periodic_timer_callback(void* arg);
|
||||
esp_timer_handle_t periodic_timer;
|
||||
|
||||
const esp_timer_create_args_t periodic_timer_args = {
|
||||
.callback = &periodic_timer_callback,
|
||||
/* name is optional, but may help identify the timer when debugging */
|
||||
.name = "periodic"
|
||||
};
|
||||
|
||||
struct data_source_buffer {
|
||||
uint8_t buffer[1024];
|
||||
uint16_t len;
|
||||
};
|
||||
|
||||
static struct data_source_buffer data_buffer = {0};
|
||||
static uint16_t MTU_size = 23;
|
||||
//In its basic form, the ANCS exposes three characteristics:
|
||||
// service UUID: 7905F431-B5CE-4E99-A40F-4B1E122D00D0
|
||||
static ble_uuid128_t APPLE_NC_UUID = BLE_UUID128_INIT(
|
||||
0xD0, 0x00, 0x2D, 0x12, 0x1E, 0x4B, 0x0F, 0xA4, 0x99, 0x4E, 0xCE, 0xB5, 0x31, 0xF4, 0x05, 0x79);
|
||||
|
||||
// Notification Source UUID: 9FBF120D-6301-42D9-8C58-25E699A21DBD(notifiable)
|
||||
static ble_uuid128_t notification_source = BLE_UUID128_INIT(
|
||||
0xbd, 0x1d, 0xa2, 0x99, 0xe6, 0x25, 0x58, 0x8c, 0xd9, 0x42, 0x01, 0x63, 0x0d, 0x12, 0xbf, 0x9f);
|
||||
// Control Point UUID:69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9(writeable with response)
|
||||
static ble_uuid128_t control_point = BLE_UUID128_INIT(
|
||||
0xd9, 0xd9, 0xaa, 0xfd, 0xbd, 0x9b, 0x21, 0x98, 0xa8, 0x49, 0xe1, 0x45, 0xf3, 0xd8, 0xd1, 0x69);
|
||||
// Data Source UUID:22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB(notifiable)
|
||||
static ble_uuid128_t data_source = BLE_UUID128_INIT(
|
||||
0xfb, 0x7b, 0x7c, 0xce, 0x6a, 0xb3, 0x44, 0xbe, 0xb5, 0x4b, 0xd6, 0x24, 0xe9, 0xc6, 0xea, 0x22);
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
static uint8_t ext_adv_pattern_1[] = {
|
||||
0x02, 0x01, 0x06,
|
||||
0x03, 0x03, 0xab, 0xcd,
|
||||
0x03, 0x03, 0x18, 0x11,
|
||||
0x0e, 0X09, 'n', 'i', 'm', 'b', 'l', 'e', '-', 'a', 'n', 'c', 's', '-', 'e',
|
||||
};
|
||||
#endif
|
||||
|
||||
static const char *tag = "NimBLE_ANCS";
|
||||
static int ble_ancs_gap_event(struct ble_gap_event *event, void *arg);
|
||||
static uint8_t own_addr_type;
|
||||
|
||||
void ble_store_config_init(void);
|
||||
|
||||
static ble_noti_attr_list_t p_attr[8] = {
|
||||
[attr_appidentifier_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDAppIdentifier,
|
||||
.attribute_len = 0,
|
||||
},
|
||||
[attr_title_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDTitle,
|
||||
.attribute_len = 0xFFFF,
|
||||
},
|
||||
[attr_subtitle_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDSubtitle,
|
||||
.attribute_len = 0xFFFF,
|
||||
},
|
||||
[attr_message_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDMessage,
|
||||
.attribute_len = 0xFFFF,
|
||||
},
|
||||
[attr_messagesize_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDMessageSize,
|
||||
.attribute_len = 0,
|
||||
},
|
||||
[attr_date_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDDate,
|
||||
.attribute_len = 0,
|
||||
},
|
||||
[attr_positiveactionlabel_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDPositiveActionLabel,
|
||||
.attribute_len = 0,
|
||||
},
|
||||
[attr_negativeactionlabel_index] = {
|
||||
.noti_attribute_id = NotificationAttributeIDNegativeActionLabel,
|
||||
.attribute_len = 0,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
void ble_get_notification_attributes(uint16_t conn_handle,
|
||||
uint16_t control_point_handle,
|
||||
uint8_t *notificationUID,
|
||||
uint8_t num_attr,
|
||||
ble_noti_attr_list_t *p_attr)
|
||||
{
|
||||
uint8_t cmd[600] = {0};
|
||||
|
||||
uint32_t index = 0;
|
||||
cmd[index++] = CommandIDGetNotificationAttributes;
|
||||
|
||||
memcpy(&cmd[index], notificationUID, ESP_NOTIFICATIONUID_LEN);
|
||||
index += ESP_NOTIFICATIONUID_LEN;
|
||||
|
||||
while (num_attr > 0) {
|
||||
cmd[index++] = p_attr->noti_attribute_id;
|
||||
|
||||
if (p_attr->attribute_len > 0) {
|
||||
cmd[index++] = (uint8_t)(p_attr->attribute_len & 0xFF);
|
||||
cmd[index++] = (uint8_t)((p_attr->attribute_len >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
p_attr++;
|
||||
num_attr--;
|
||||
}
|
||||
|
||||
int rc = ble_gattc_write_flat(conn_handle,
|
||||
control_point_handle,
|
||||
cmd,
|
||||
index,
|
||||
NULL, // no callback
|
||||
NULL); // no argument
|
||||
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(WARN, "Failed to write notification attribute request: rc=%d\n", rc);
|
||||
|
||||
}
|
||||
}
|
||||
void ble_perform_notification_action(uint8_t *notificationUID,
|
||||
uint8_t ActionID,
|
||||
uint16_t conn_handle,
|
||||
uint16_t control_point_handle)
|
||||
{
|
||||
uint8_t buffer[600] = {0};
|
||||
|
||||
uint16_t index = 0;
|
||||
buffer[index++] = CommandIDPerformNotificationAction; // define this as needed
|
||||
|
||||
memcpy(&buffer[index], notificationUID, ESP_NOTIFICATIONUID_LEN);
|
||||
index += ESP_NOTIFICATIONUID_LEN;
|
||||
|
||||
buffer[index++] = ActionID;
|
||||
|
||||
int rc = ble_gattc_write_flat(conn_handle,
|
||||
control_point_handle,
|
||||
buffer,
|
||||
index,
|
||||
NULL, // no callback
|
||||
NULL); // no callback argument
|
||||
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(WARN, "Failed to write perform action command: rc=%d\n", rc);
|
||||
}
|
||||
}
|
||||
|
||||
static void periodic_timer_callback(void* arg)
|
||||
{
|
||||
esp_timer_stop(periodic_timer);
|
||||
if (data_buffer.len > 0) {
|
||||
ble_receive_apple_data_source(data_buffer.buffer, data_buffer.len);
|
||||
memset(data_buffer.buffer, 0, data_buffer.len);
|
||||
data_buffer.len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ancs_on_custom_subscribe(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr,
|
||||
void *arg)
|
||||
{
|
||||
|
||||
MODLOG_DFLT(INFO,
|
||||
"Subscribe to the custom subscribable characteristic complete; "
|
||||
"status=%d conn_handle=%d",
|
||||
error->status, conn_handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int ancs_dsc_discovered_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
|
||||
void *arg)
|
||||
{
|
||||
int rc = 0;
|
||||
uint8_t cccd_val[2] = {0x01, 0x00}; // Enable notification
|
||||
if (error->status == 0) {
|
||||
if (ble_uuid_cmp(&dsc->uuid.u, BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16)) == 0) {
|
||||
rc = ble_gattc_write_flat(conn_handle,
|
||||
dsc->handle,
|
||||
cccd_val, sizeof(cccd_val),
|
||||
ancs_on_custom_subscribe, NULL);
|
||||
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(WARN, "Failed to subscribe to (rc=%d)", rc);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rc = error->status;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
ancs_chr_discovered_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_chr *chr, void *arg)
|
||||
{
|
||||
int rc = 0;
|
||||
if (error->status == 0) {
|
||||
/* Notification Source */
|
||||
if ((chr->properties & BLE_GATT_CHR_PROP_NOTIFY) &&
|
||||
ble_uuid_cmp(&chr->uuid.u, ¬ification_source.u) == 0) {
|
||||
|
||||
notification_source_handle = chr->val_handle;
|
||||
rc = ble_gattc_disc_all_dscs(conn_handle, chr->val_handle, svc_e_handle, ancs_dsc_discovered_cb, NULL);
|
||||
MODLOG_DFLT(INFO, "Found Notification Source characnteristic");
|
||||
|
||||
}
|
||||
/* Data Source */
|
||||
else if ((chr->properties & BLE_GATT_CHR_PROP_NOTIFY) &&
|
||||
ble_uuid_cmp(&chr->uuid.u, &data_source.u) == 0) {
|
||||
|
||||
data_source_handle = chr->val_handle;
|
||||
rc = ble_gattc_disc_all_dscs(conn_handle, chr->val_handle, svc_e_handle, ancs_dsc_discovered_cb, NULL);
|
||||
MODLOG_DFLT(INFO, "Found Data Source characteristic");
|
||||
|
||||
}
|
||||
/* Control Point */
|
||||
else if ((chr->properties & BLE_GATT_CHR_PROP_WRITE) &&
|
||||
ble_uuid_cmp(&chr->uuid.u, &control_point.u) == 0) {
|
||||
|
||||
control_point_handle = chr->val_handle;
|
||||
MODLOG_DFLT(INFO, "Found Control Point characteristic");
|
||||
}
|
||||
} else{
|
||||
rc = error->status;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int ancs_service_discovered_cb(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_svc *svc, void *arg)
|
||||
{
|
||||
int rc ;
|
||||
if (error->status == 0) {
|
||||
if (svc == NULL) {
|
||||
MODLOG_DFLT(WARN, "ANCS service not found");
|
||||
return -1;
|
||||
}
|
||||
|
||||
svc_e_handle = svc->end_handle;
|
||||
/* discover characteristics within this service range */
|
||||
rc = ble_gattc_disc_all_chrs(conn_handle, svc->start_handle, svc->end_handle, ancs_chr_discovered_cb, NULL);
|
||||
} else {
|
||||
rc = error->status;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
/**
|
||||
* Logs information about a connection to the console.
|
||||
*/
|
||||
static void
|
||||
ble_ancs_print_conn_desc(struct ble_gap_conn_desc *desc)
|
||||
{
|
||||
MODLOG_DFLT(INFO, "handle=%d our_ota_addr_type=%d our_ota_addr=",
|
||||
desc->conn_handle, desc->our_ota_addr.type);
|
||||
print_addr(desc->our_ota_addr.val);
|
||||
MODLOG_DFLT(INFO, " our_id_addr_type=%d our_id_addr=",
|
||||
desc->our_id_addr.type);
|
||||
print_addr(desc->our_id_addr.val);
|
||||
MODLOG_DFLT(INFO, " peer_ota_addr_type=%d peer_ota_addr=",
|
||||
desc->peer_ota_addr.type);
|
||||
print_addr(desc->peer_ota_addr.val);
|
||||
MODLOG_DFLT(INFO, " peer_id_addr_type=%d peer_id_addr=",
|
||||
desc->peer_id_addr.type);
|
||||
print_addr(desc->peer_id_addr.val);
|
||||
MODLOG_DFLT(INFO, " conn_itvl=%d conn_latency=%d supervision_timeout=%d "
|
||||
"encrypted=%d authenticated=%d bonded=%d\n",
|
||||
desc->conn_itvl, desc->conn_latency,
|
||||
desc->supervision_timeout,
|
||||
desc->sec_state.encrypted,
|
||||
desc->sec_state.authenticated,
|
||||
desc->sec_state.bonded);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
/**
|
||||
* Enables advertising with the following parameters:
|
||||
* o General discoverable mode.
|
||||
* o Undirected connectable mode.
|
||||
*/
|
||||
static void
|
||||
ext_ble_ancs_advertise(void)
|
||||
{
|
||||
struct ble_gap_ext_adv_params params;
|
||||
struct os_mbuf *data;
|
||||
uint8_t instance = 0;
|
||||
int rc;
|
||||
|
||||
/* First check if any instance is already active */
|
||||
if(ble_gap_ext_adv_active(instance)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* use defaults for non-set params */
|
||||
memset (¶ms, 0, sizeof(params));
|
||||
|
||||
/* enable connectable advertising */
|
||||
params.connectable = 1;
|
||||
|
||||
/* advertise using random addr */
|
||||
params.own_addr_type = BLE_OWN_ADDR_PUBLIC;
|
||||
|
||||
params.primary_phy = BLE_HCI_LE_PHY_1M;
|
||||
params.secondary_phy = BLE_HCI_LE_PHY_2M;
|
||||
//params.tx_power = 127;
|
||||
params.sid = 1;
|
||||
|
||||
params.itvl_min = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
|
||||
params.itvl_max = BLE_GAP_ADV_FAST_INTERVAL1_MIN;
|
||||
|
||||
/* configure instance 0 */
|
||||
rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL,
|
||||
ble_ancs_gap_event, NULL);
|
||||
assert (rc == 0);
|
||||
|
||||
/* in this case only scan response is allowed */
|
||||
|
||||
/* get mbuf for scan rsp data */
|
||||
data = os_msys_get_pkthdr(sizeof(ext_adv_pattern_1), 0);
|
||||
assert(data);
|
||||
|
||||
/* fill mbuf with scan rsp data */
|
||||
rc = os_mbuf_append(data, ext_adv_pattern_1, sizeof(ext_adv_pattern_1));
|
||||
assert(rc == 0);
|
||||
|
||||
rc = ble_gap_ext_adv_set_data(instance, data);
|
||||
assert (rc == 0);
|
||||
|
||||
/* start advertising */
|
||||
rc = ble_gap_ext_adv_start(instance, 0, 0);
|
||||
assert (rc == 0);
|
||||
}
|
||||
#else
|
||||
/**
|
||||
* Enables advertising with the following parameters:
|
||||
* o General discoverable mode.
|
||||
* o Undirected connectable mode.
|
||||
*/
|
||||
static void
|
||||
ble_ancs_advertise(void)
|
||||
{
|
||||
struct ble_gap_adv_params adv_params;
|
||||
struct ble_hs_adv_fields fields;
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
const char *name;
|
||||
#endif
|
||||
int rc;
|
||||
|
||||
/**
|
||||
* Set the advertisement data included in our advertisements:
|
||||
* o Flags (indicates advertisement type and other general info).
|
||||
* o Advertising tx power.
|
||||
* o Device name.
|
||||
* o 16-bit service UUIDs (alert notifications).
|
||||
*/
|
||||
|
||||
memset(&fields, 0, sizeof fields);
|
||||
|
||||
/* Advertise two flags:
|
||||
* o Discoverability in forthcoming advertisement (general)
|
||||
* o BLE-only (BR/EDR unsupported).
|
||||
*/
|
||||
fields.flags = BLE_HS_ADV_F_DISC_GEN |
|
||||
BLE_HS_ADV_F_BREDR_UNSUP;
|
||||
|
||||
/* Indicate that the TX power level field should be included; have the
|
||||
* stack fill this value automatically. This is done by assigning the
|
||||
* special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
|
||||
*/
|
||||
fields.tx_pwr_lvl_is_present = 1;
|
||||
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
|
||||
|
||||
name = ble_svc_gap_device_name();
|
||||
fields.name = (uint8_t *)name;
|
||||
fields.name_len = strlen(name);
|
||||
fields.name_is_complete = 1;
|
||||
|
||||
fields.num_uuids16 = 1;
|
||||
fields.uuids16_is_complete = 1;
|
||||
|
||||
rc = ble_gap_adv_set_fields(&fields);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error setting advertisement data; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Begin advertising. */
|
||||
memset(&adv_params, 0, sizeof adv_params);
|
||||
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
|
||||
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
|
||||
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
|
||||
&adv_params, ble_ancs_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error enabling advertisement; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The nimble host executes this callback when a GAP event occurs. The
|
||||
* application associates a GAP event callback with each connection that forms.
|
||||
* ble_ancs uses the same callback for all connections.
|
||||
*
|
||||
* @param event The type of event being signalled.
|
||||
* @param ctxt Various information pertaining to the event.
|
||||
* @param arg Application-specified argument; unused by
|
||||
* ble_ancs.
|
||||
*
|
||||
* @return 0 if the application successfully handled the
|
||||
* event; nonzero on failure. The semantics
|
||||
* of the return code is specific to the
|
||||
* particular GAP event being signalled.
|
||||
*/
|
||||
static int
|
||||
ble_ancs_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
struct ble_gap_conn_desc desc;
|
||||
int rc;
|
||||
#endif
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
/* A new connection was established or a connection attempt failed. */
|
||||
MODLOG_DFLT(INFO, "connection %s; status=%d ",
|
||||
event->connect.status == 0 ? "established" : "failed",
|
||||
event->connect.status);
|
||||
if (event->connect.status == 0) {
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
ble_ancs_print_conn_desc(&desc);
|
||||
}
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
|
||||
if (event->connect.status != 0) {
|
||||
/* Connection failed; resume advertising. */
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
ext_ble_ancs_advertise();
|
||||
#else
|
||||
ble_ancs_advertise();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Initiate security - It will perform
|
||||
* Pairing (Exchange keys)
|
||||
* Bonding (Store keys)
|
||||
* Encryption (Enable encryption)
|
||||
* Will invoke event BLE_GAP_EVENT_ENC_CHANGE
|
||||
**/
|
||||
rc = ble_gap_security_initiate(event->connect.conn_handle);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc);
|
||||
return ble_gap_terminate(event->connect.conn_handle,
|
||||
BLE_ERR_REM_USER_CONN_TERM);
|
||||
} else {
|
||||
MODLOG_DFLT(INFO, "Connection secured\n");
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
MODLOG_DFLT(INFO, "disconnect; reason=%d ", event->disconnect.reason);
|
||||
ble_ancs_print_conn_desc(&event->disconnect.conn);
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
|
||||
/* Connection terminated; resume advertising. */
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
ext_ble_ancs_advertise();
|
||||
#else
|
||||
ble_ancs_advertise();
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_CONN_UPDATE:
|
||||
/* The central has updated the connection parameters. */
|
||||
MODLOG_DFLT(INFO, "connection updated; status=%d ",
|
||||
event->conn_update.status);
|
||||
rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
ble_ancs_print_conn_desc(&desc);
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_ADV_COMPLETE:
|
||||
MODLOG_DFLT(INFO, "advertise complete; reason=%d",
|
||||
event->adv_complete.reason);
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
ext_ble_ancs_advertise();
|
||||
#else
|
||||
ble_ancs_advertise();
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_ENC_CHANGE:
|
||||
/* Encryption has been enabled or disabled for this connection. */
|
||||
MODLOG_DFLT(INFO, "encryption change event; status=%d ",
|
||||
event->enc_change.status);
|
||||
rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
ble_ancs_print_conn_desc(&desc);
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
rc = ble_gattc_disc_svc_by_uuid(event->connect.conn_handle, &APPLE_NC_UUID.u,
|
||||
ancs_service_discovered_cb, NULL);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_NOTIFY_TX:
|
||||
MODLOG_DFLT(INFO, "notify_tx event; conn_handle=%d attr_handle=%d "
|
||||
"status=%d is_indication=%d",
|
||||
event->notify_tx.conn_handle,
|
||||
event->notify_tx.attr_handle,
|
||||
event->notify_tx.status,
|
||||
event->notify_tx.indication);
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_NOTIFY_RX:
|
||||
/* Peer sent us a notification or indication. */
|
||||
if (event->notify_rx.attr_handle == notification_source_handle) {
|
||||
ble_receive_apple_notification_source(event->notify_rx.om->om_data, event->notify_rx.om->om_len);
|
||||
uint8_t *notificationUID = &event->notify_rx.om->om_data[4];
|
||||
if (event->notify_rx.om->om_data[0] == EventIDNotificationAdded &&
|
||||
event->notify_rx.om->om_data[2] == CategoryIDIncomingCall) {
|
||||
MODLOG_DFLT(INFO, "IncomingCall, reject");
|
||||
ble_perform_notification_action(notificationUID, ActionIDNegative, event->notify_rx.conn_handle, control_point_handle);
|
||||
} else if (event->notify_rx.om->om_data[0] == EventIDNotificationAdded) {
|
||||
MODLOG_DFLT(INFO, "Get detailed information");
|
||||
ble_get_notification_attributes(event->notify_rx.conn_handle, control_point_handle,
|
||||
notificationUID, sizeof(p_attr)/sizeof(ble_noti_attr_list_t), p_attr);
|
||||
}
|
||||
} else if (event->notify_rx.attr_handle == data_source_handle) {
|
||||
memcpy(&data_buffer.buffer[data_buffer.len],
|
||||
event->notify_rx.om->om_data,
|
||||
event->notify_rx.om->om_len);
|
||||
data_buffer.len += event->notify_rx.om->om_len;
|
||||
|
||||
if (event->notify_rx.om->om_len == (MTU_size - 3)) {
|
||||
esp_timer_start_periodic(periodic_timer, 500000);
|
||||
} else {
|
||||
esp_timer_stop(periodic_timer);
|
||||
ble_receive_apple_data_source(data_buffer.buffer, data_buffer.len);
|
||||
memset(data_buffer.buffer, 0, data_buffer.len);
|
||||
data_buffer.len = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
MODLOG_DFLT(INFO, "unknown handle, receive notify value:" );
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_SUBSCRIBE:
|
||||
MODLOG_DFLT(INFO, "subscribe event; conn_handle=%d attr_handle=%d "
|
||||
"reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
|
||||
event->subscribe.conn_handle,
|
||||
event->subscribe.attr_handle,
|
||||
event->subscribe.reason,
|
||||
event->subscribe.prev_notify,
|
||||
event->subscribe.cur_notify,
|
||||
event->subscribe.prev_indicate,
|
||||
event->subscribe.cur_indicate);
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_MTU:
|
||||
MTU_size = event->mtu.value;
|
||||
MODLOG_DFLT(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n",
|
||||
event->mtu.conn_handle,
|
||||
event->mtu.channel_id,
|
||||
event->mtu.value);
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_REPEAT_PAIRING:
|
||||
/* We already have a bond with the peer, but it is attempting to
|
||||
* establish a new secure link. This app sacrifices security for
|
||||
* convenience: just throw away the old bond and accept the new link.
|
||||
*/
|
||||
|
||||
/* Delete the old bond. */
|
||||
rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
ble_store_util_delete_peer(&desc.peer_id_addr);
|
||||
|
||||
/* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
|
||||
* continue with the pairing operation.
|
||||
*/
|
||||
return BLE_GAP_REPEAT_PAIRING_RETRY;
|
||||
|
||||
case BLE_GAP_EVENT_PASSKEY_ACTION:
|
||||
ESP_LOGI(tag, "PASSKEY_ACTION_EVENT started");
|
||||
struct ble_sm_io pkey = {0};
|
||||
int key = 0;
|
||||
|
||||
if (event->passkey.params.action == BLE_SM_IOACT_DISP) {
|
||||
pkey.action = event->passkey.params.action;
|
||||
pkey.passkey = 123456; // This is the passkey to be entered on peer
|
||||
ESP_LOGI(tag, "Enter passkey %" PRIu32 "on the peer side", pkey.passkey);
|
||||
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
||||
ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc);
|
||||
} else if (event->passkey.params.action == BLE_SM_IOACT_NUMCMP) {
|
||||
ESP_LOGI(tag, "Passkey on device's display: %" PRIu32 , event->passkey.params.numcmp);
|
||||
ESP_LOGI(tag, "Accept or reject the passkey through console in this format -> key Y or key N");
|
||||
pkey.action = event->passkey.params.action;
|
||||
if (scli_receive_key(&key)) {
|
||||
pkey.numcmp_accept = key;
|
||||
} else {
|
||||
pkey.numcmp_accept = 0;
|
||||
ESP_LOGE(tag, "Timeout! Rejecting the key");
|
||||
}
|
||||
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
||||
ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc);
|
||||
} else if (event->passkey.params.action == BLE_SM_IOACT_OOB) {
|
||||
static uint8_t tem_oob[16] = {0};
|
||||
pkey.action = event->passkey.params.action;
|
||||
for (int i = 0; i < 16; i++) {
|
||||
pkey.oob[i] = tem_oob[i];
|
||||
}
|
||||
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
||||
ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc);
|
||||
} else if (event->passkey.params.action == BLE_SM_IOACT_INPUT) {
|
||||
ESP_LOGI(tag, "Enter the passkey through console in this format-> key 123456");
|
||||
pkey.action = event->passkey.params.action;
|
||||
if (scli_receive_key(&key)) {
|
||||
pkey.passkey = key;
|
||||
} else {
|
||||
pkey.passkey = 0;
|
||||
ESP_LOGE(tag, "Timeout! Passing 0 as the key");
|
||||
}
|
||||
rc = ble_sm_inject_io(event->passkey.conn_handle, &pkey);
|
||||
ESP_LOGI(tag, "ble_sm_inject_io result: %d", rc);
|
||||
}
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
ble_ancs_on_reset(int reason)
|
||||
{
|
||||
MODLOG_DFLT(ERROR, "Resetting state; reason=%d\n", reason);
|
||||
}
|
||||
|
||||
static void
|
||||
ble_ancs_on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Printing ADDR */
|
||||
uint8_t addr_val[6] = {0};
|
||||
rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL);
|
||||
|
||||
MODLOG_DFLT(INFO, "Device Address: ");
|
||||
print_addr(addr_val);
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
/* Begin advertising. */
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
ext_ble_ancs_advertise();
|
||||
#else
|
||||
ble_ancs_advertise();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ble_ancs_host_task(void *param)
|
||||
{
|
||||
ESP_LOGI(tag, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
void
|
||||
app_main(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
/* Initialize NVS — it is used to store PHY calibration data */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ret = nimble_port_init();
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(tag, "Failed to init nimble %d ", ret);
|
||||
return;
|
||||
}
|
||||
/* Initialize the NimBLE host configuration. */
|
||||
ble_hs_cfg.reset_cb = ble_ancs_on_reset;
|
||||
ble_hs_cfg.sync_cb = ble_ancs_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
ble_hs_cfg.sm_bonding = 1;
|
||||
/* Enable the appropriate bit masks to make sure the keys
|
||||
* that are needed are exchanged
|
||||
*/
|
||||
ble_hs_cfg.sm_our_key_dist |= BLE_SM_PAIR_KEY_DIST_ENC;
|
||||
ble_hs_cfg.sm_their_key_dist |= BLE_SM_PAIR_KEY_DIST_ENC;
|
||||
ble_hs_cfg.sm_sc = 0;
|
||||
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-ancs");
|
||||
assert(rc == 0);
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
nimble_port_freertos_init(ble_ancs_host_task);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_NVS_PERSIST=y
|
||||
@@ -568,8 +568,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,45 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,48 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_DYNAMIC_SERVICE=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -622,8 +622,13 @@ app_main(void)
|
||||
ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_KEYBOARD_ONLY;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=n
|
||||
CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_SIZE=70
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=n
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,565 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "host/ble_hs.h"
|
||||
#include "host/util/util.h"
|
||||
#include "services/gap/ble_svc_gap.h"
|
||||
#include "services/gatt/ble_svc_gatt.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "blecoex.h"
|
||||
#include "services/ans/ble_svc_ans.h"
|
||||
|
||||
static uint8_t own_addr_type;
|
||||
static int blecoex_gap_event(struct ble_gap_event *event, void *arg);
|
||||
void ble_coex_advertise(void);
|
||||
void ble_coex_scan(void);
|
||||
static bool client_connect = 0;
|
||||
|
||||
static int gatt_svr_access_cb(uint16_t conn_handle, uint16_t attr_handle,
|
||||
struct ble_gatt_access_ctxt *ctxt, void *arg) {
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
|
||||
static uint8_t data[1] = {42}; // Example value
|
||||
os_mbuf_append(ctxt->om, data, sizeof(data));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const ble_uuid128_t gatt_svr_svc_uuid =
|
||||
BLE_UUID128_INIT(0x2d, 0x71, 0xa2, 0x59, 0xb4, 0x58, 0xc8, 0x12,
|
||||
0x99, 0x99, 0x43, 0x95, 0x12, 0x2f, 0x46, 0x59);
|
||||
|
||||
/* A characteristic that can be subscribed to */
|
||||
static uint16_t gatt_svr_chr_val_handle;
|
||||
static const ble_uuid128_t gatt_svr_chr_uuid =
|
||||
BLE_UUID128_INIT(0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x11, 0x11,
|
||||
0x22, 0x22, 0x22, 0x22, 0x33, 0x33, 0x33, 0x33);
|
||||
|
||||
/* A custom descriptor */
|
||||
static const ble_uuid128_t gatt_svr_dsc_uuid =
|
||||
BLE_UUID128_INIT(0x01, 0x01, 0x01, 0x01, 0x12, 0x12, 0x12, 0x12,
|
||||
0x23, 0x23, 0x23, 0x23, 0x34, 0x34, 0x34, 0x34);
|
||||
|
||||
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
|
||||
{
|
||||
/*** Service ***/
|
||||
.type = BLE_GATT_SVC_TYPE_PRIMARY,
|
||||
.uuid = &gatt_svr_svc_uuid.u,
|
||||
.characteristics = (struct ble_gatt_chr_def[])
|
||||
{ {
|
||||
/*** This characteristic can be subscribed to by writing 0x00 and 0x01 to the CCCD ***/
|
||||
.uuid = &gatt_svr_chr_uuid.u,
|
||||
.access_cb = gatt_svr_access_cb,
|
||||
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_NOTIFY | BLE_GATT_CHR_F_INDICATE,
|
||||
.val_handle = &gatt_svr_chr_val_handle,
|
||||
.descriptors = (struct ble_gatt_dsc_def[])
|
||||
{ {
|
||||
.uuid = &gatt_svr_dsc_uuid.u,
|
||||
.att_flags = BLE_ATT_F_READ,
|
||||
.access_cb = gatt_svr_access_cb,
|
||||
}, {
|
||||
0, /* No more descriptors in this characteristic */
|
||||
}
|
||||
},
|
||||
}, {
|
||||
0, /* No more characteristics in this service. */
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
0, /* No more services. */
|
||||
},
|
||||
};
|
||||
|
||||
static int
|
||||
blecoex_should_connect(const struct ble_gap_disc_desc *disc)
|
||||
{
|
||||
struct ble_hs_adv_fields fields;
|
||||
int rc;
|
||||
int i;
|
||||
|
||||
/* The device has to be advertising connectability. */
|
||||
if (disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
|
||||
disc->event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = ble_hs_adv_parse_fields(&fields, disc->data, disc->length_data);
|
||||
if (rc != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The device has to advertise support for the Alert Notification
|
||||
* service (0x1811).
|
||||
*/
|
||||
for (i = 0; i < fields.num_uuids16; i++) {
|
||||
if (ble_uuid_u16(&fields.uuids16[i].u) == BLECOEX_SVC_ALERT_UUID) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
connect_if_interesting(void *disc)
|
||||
{
|
||||
uint8_t own_addr_type;
|
||||
int rc;
|
||||
ble_addr_t *addr;
|
||||
|
||||
/* Don't do anything if we don't care about this advertiser. */
|
||||
if (!blecoex_should_connect((struct ble_gap_disc_desc *)disc)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Scanning must be stopped before a connection can be initiated. */
|
||||
rc = ble_gap_disc_cancel();
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(DEBUG, "Failed to cancel scan; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Figure out address to use for connect (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for
|
||||
* timeout.
|
||||
*/
|
||||
addr = &((struct ble_gap_disc_desc *)disc)->addr;
|
||||
|
||||
rc = ble_gap_connect(own_addr_type, addr, 30000, NULL,
|
||||
blecoex_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Failed to connect to device \n");
|
||||
return;
|
||||
}
|
||||
|
||||
client_connect = 1;
|
||||
}
|
||||
|
||||
static int
|
||||
blecent_on_subscribe(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr,
|
||||
void *arg)
|
||||
{
|
||||
MODLOG_DFLT(INFO, "Subscribe complete; status=%d conn_handle=%d "
|
||||
"attr_handle=%d\n",
|
||||
error->status, conn_handle, attr->handle);
|
||||
|
||||
/* Terminate connection */
|
||||
ble_gap_terminate(conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
blecent_on_write(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr,
|
||||
void *arg)
|
||||
{
|
||||
MODLOG_DFLT(INFO,
|
||||
"Write complete; status=%d conn_handle=%d attr_handle=%d\n",
|
||||
error->status, conn_handle, attr->handle);
|
||||
|
||||
/* Subscribe to notifications for the Unread Alert Status characteristic.
|
||||
* A central enables notifications by writing two bytes (1, 0) to the
|
||||
* characteristic's client-characteristic-configuration-descriptor (CCCD).
|
||||
*/
|
||||
const struct peer_dsc *dsc;
|
||||
uint8_t value[2];
|
||||
int rc;
|
||||
const struct peer *peer = peer_find(conn_handle);
|
||||
|
||||
dsc = peer_dsc_find_uuid(peer,
|
||||
BLE_UUID16_DECLARE(BLECOEX_SVC_ALERT_UUID),
|
||||
BLE_UUID16_DECLARE(BLECOEX_CHR_UNR_ALERT_STAT_UUID),
|
||||
BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16));
|
||||
if (dsc == NULL) {
|
||||
MODLOG_DFLT(ERROR, "Error: Peer lacks a CCCD for the Unread Alert "
|
||||
"Status characteristic\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
value[0] = 1;
|
||||
value[1] = 0;
|
||||
rc = ble_gattc_write_flat(conn_handle, dsc->dsc.handle,
|
||||
value, sizeof value, blecent_on_subscribe, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Error: Failed to subscribe to characteristic; "
|
||||
"rc=%d\n", rc);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
/* Terminate the connection. */
|
||||
return ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
blecent_on_read(uint16_t conn_handle,
|
||||
const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr,
|
||||
void *arg)
|
||||
{
|
||||
MODLOG_DFLT(INFO, "Read complete; status=%d conn_handle=%d", error->status,
|
||||
conn_handle);
|
||||
if (error->status == 0) {
|
||||
MODLOG_DFLT(INFO, " attr_handle=%d value=", attr->handle);
|
||||
print_mbuf(attr->om);
|
||||
}
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
|
||||
/* Write two bytes (99, 100) to the alert-notification-control-point
|
||||
* characteristic.
|
||||
*/
|
||||
const struct peer_chr *chr;
|
||||
uint8_t value[2];
|
||||
int rc;
|
||||
const struct peer *peer = peer_find(conn_handle);
|
||||
|
||||
chr = peer_chr_find_uuid(peer,
|
||||
BLE_UUID16_DECLARE(BLECOEX_SVC_ALERT_UUID),
|
||||
BLE_UUID16_DECLARE(BLECOEX_CHR_ALERT_NOT_CTRL_PT));
|
||||
if (chr == NULL) {
|
||||
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Alert "
|
||||
"Notification Control Point characteristic\n");
|
||||
goto err;
|
||||
}
|
||||
value[0] = 99;
|
||||
value[1] = 100;
|
||||
rc = ble_gattc_write_flat(conn_handle, chr->chr.val_handle,
|
||||
value, sizeof value, blecent_on_write, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Error: Failed to write characteristic; rc=%d\n",
|
||||
rc);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err:
|
||||
/* Terminate the connection. */
|
||||
return ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
blecent_read_write_subscribe(const struct peer *peer)
|
||||
{
|
||||
const struct peer_chr *chr;
|
||||
int rc;
|
||||
|
||||
/* Read the supported-new-alert-category characteristic. */
|
||||
chr = peer_chr_find_uuid(peer,
|
||||
BLE_UUID16_DECLARE(BLECOEX_SVC_ALERT_UUID),
|
||||
BLE_UUID16_DECLARE(BLECOEX_CHR_SUP_NEW_ALERT_CAT_UUID));
|
||||
if (chr == NULL) {
|
||||
MODLOG_DFLT(ERROR, "Error: Peer doesn't support the Supported New "
|
||||
"Alert Category characteristic\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
rc = ble_gattc_read(peer->conn_handle, chr->chr.val_handle,
|
||||
blecent_on_read, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Error: Failed to read characteristic; rc=%d\n",
|
||||
rc);
|
||||
goto err;
|
||||
}
|
||||
|
||||
return;
|
||||
err:
|
||||
/* Terminate the connection. */
|
||||
ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
blecent_on_disc_complete(const struct peer *peer, int status, void *arg)
|
||||
{
|
||||
|
||||
if (status != 0) {
|
||||
/* Service discovery failed. Terminate the connection. */
|
||||
MODLOG_DFLT(ERROR, "Error: Service discovery failed; status=%d "
|
||||
"conn_handle=%d\n", status, peer->conn_handle);
|
||||
ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Service discovery has completed successfully. Now we have a complete
|
||||
* list of services, characteristics, and descriptors that the peer
|
||||
* supports.
|
||||
*/
|
||||
MODLOG_DFLT(INFO, "Service discovery complete; status=%d "
|
||||
"conn_handle=%d\n", status, peer->conn_handle);
|
||||
|
||||
/* Now perform three GATT procedures against the peer: read,
|
||||
* write, and subscribe to notifications for the ANS service.
|
||||
*/
|
||||
blecent_read_write_subscribe(peer);
|
||||
}
|
||||
|
||||
static void restart_coex(void)
|
||||
{
|
||||
client_connect = 0;
|
||||
ble_gap_adv_stop();
|
||||
ble_coex_advertise();
|
||||
//TODO: Current example only restarts advertising.
|
||||
#if 0
|
||||
ble_gap_disc_cancel();
|
||||
ble_coex_scan();
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
blecoex_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
struct ble_gap_conn_desc desc;
|
||||
int rc;
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_DISC:
|
||||
connect_if_interesting(&event->disc);
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
MODLOG_DFLT(INFO, "%s connection %s; status=%d ",
|
||||
client_connect == 1 ? "Client" : "Server",
|
||||
event->connect.status == 0 ? "established" : "failed",
|
||||
event->connect.status);
|
||||
|
||||
if (event->connect.status == 0 ) {
|
||||
rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
MODLOG_DFLT(INFO, "\n");
|
||||
|
||||
const uint8_t *u8p;
|
||||
MODLOG_DFLT(INFO, " peer_ota_addr_type=%d peer_ota_addr=",
|
||||
desc.peer_ota_addr.type);
|
||||
u8p = desc.peer_ota_addr.val;
|
||||
MODLOG_DFLT(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
|
||||
MODLOG_DFLT(INFO, " peer_id_addr_type=%d peer_id_addr=",
|
||||
desc.peer_id_addr.type);
|
||||
u8p = desc.peer_id_addr.val;
|
||||
MODLOG_DFLT(INFO, "%02x:%02x:%02x:%02x:%02x:%02x",
|
||||
u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
|
||||
|
||||
}
|
||||
|
||||
if (client_connect == 1 ) {
|
||||
client_connect = 2;
|
||||
|
||||
/* Remember peer. */
|
||||
rc = peer_add(event->connect.conn_handle);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc);
|
||||
restart_coex();
|
||||
}
|
||||
|
||||
/* Perform service discovery */
|
||||
rc = peer_disc_all(event->connect.conn_handle,
|
||||
blecent_on_disc_complete, NULL);
|
||||
if(rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
|
||||
restart_coex();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_DISCONNECT:
|
||||
MODLOG_DFLT(INFO, "Disconnect \n");
|
||||
restart_coex();
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_DISC_COMPLETE:
|
||||
MODLOG_DFLT(INFO, "Discovery completed \n");
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_SUBSCRIBE:
|
||||
MODLOG_DFLT(INFO, "subscribe event; conn_handle=%d attr_handle=%d "
|
||||
"reason=%d prevn=%d curn=%d previ=%d curi=%d\n",
|
||||
event->subscribe.conn_handle,
|
||||
event->subscribe.attr_handle,
|
||||
event->subscribe.reason,
|
||||
event->subscribe.prev_notify,
|
||||
event->subscribe.cur_notify,
|
||||
event->subscribe.prev_indicate,
|
||||
event->subscribe.cur_indicate);
|
||||
return 0;
|
||||
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ble_coex_scan(void)
|
||||
{
|
||||
uint8_t own_addr_type;
|
||||
struct ble_gap_disc_params disc_params = {0};
|
||||
int rc;
|
||||
|
||||
/* Figure out address to use while advertising (no privacy for now) */
|
||||
rc = ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error determining address type; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Tell the controller to filter duplicates; we don't want to process
|
||||
* repeated advertisements from the same device.
|
||||
*/
|
||||
disc_params.filter_duplicates = 1;
|
||||
|
||||
/**
|
||||
* Perform a passive scan. I.e., don't send follow-up scan requests to
|
||||
* each advertiser.
|
||||
*/
|
||||
disc_params.passive = 1;
|
||||
|
||||
/* Use defaults for the rest of the parameters. */
|
||||
disc_params.itvl = 0;
|
||||
disc_params.window = 0;
|
||||
disc_params.filter_policy = 0;
|
||||
disc_params.limited = 0;
|
||||
|
||||
/* Start discovery for 120 seconds */
|
||||
rc = ble_gap_disc(own_addr_type, (120*1000) , &disc_params,
|
||||
blecoex_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "Error initiating GAP discovery procedure; rc=%d\n",
|
||||
rc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ble_coex_advertise(void)
|
||||
{
|
||||
struct ble_gap_adv_params adv_params;
|
||||
struct ble_hs_adv_fields fields;
|
||||
const char *name;
|
||||
int rc;
|
||||
|
||||
/**
|
||||
* Set the advertisement data included in our advertisements:
|
||||
* o Flags (indicates advertisement type and other general info).
|
||||
* o Advertising tx power.
|
||||
* o Device name.
|
||||
* o 16-bit service UUIDs (alert notifications).
|
||||
*/
|
||||
|
||||
memset(&fields, 0, sizeof fields);
|
||||
|
||||
/* Advertise two flags:
|
||||
* o Discoverability in forthcoming advertisement (general)
|
||||
* o BLE-only (BR/EDR unsupported).
|
||||
*/
|
||||
fields.flags = BLE_HS_ADV_F_DISC_GEN |
|
||||
BLE_HS_ADV_F_BREDR_UNSUP;
|
||||
|
||||
/* Indicate that the TX power level field should be included; have the
|
||||
* stack fill this value automatically. This is done by assigning the
|
||||
* special value BLE_HS_ADV_TX_PWR_LVL_AUTO.
|
||||
*/
|
||||
fields.tx_pwr_lvl_is_present = 1;
|
||||
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
|
||||
|
||||
name = ble_svc_gap_device_name();
|
||||
fields.name = (uint8_t *)name;
|
||||
fields.name_len = strlen(name);
|
||||
fields.name_is_complete = 1;
|
||||
|
||||
fields.uuids16 = (ble_uuid16_t[]) {
|
||||
BLE_UUID16_INIT(BLECOEX_SVC_ALERT_UUID)
|
||||
};
|
||||
fields.num_uuids16 = 1;
|
||||
fields.uuids16_is_complete = 1;
|
||||
|
||||
rc = ble_gap_adv_set_fields(&fields);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error setting advertisement data; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Begin advertising. */
|
||||
memset(&adv_params, 0, sizeof adv_params);
|
||||
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
|
||||
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
|
||||
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
|
||||
&adv_params, blecoex_gap_event, NULL);
|
||||
if (rc != 0) {
|
||||
MODLOG_DFLT(ERROR, "error enabling advertisement; rc=%d\n", rc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void on_sync(void)
|
||||
{
|
||||
int rc;
|
||||
|
||||
ble_hs_util_ensure_addr(0);
|
||||
|
||||
ble_hs_id_infer_auto(0, &own_addr_type);
|
||||
ble_svc_gap_device_name_set("NimBLE Coex");
|
||||
ble_coex_advertise();
|
||||
|
||||
// Start scanning as a client
|
||||
rc = ble_hs_util_ensure_addr(0);
|
||||
assert(rc == 0);
|
||||
|
||||
ble_coex_scan();
|
||||
}
|
||||
|
||||
void ble_hs_task(void *param)
|
||||
{
|
||||
MODLOG_DFLT(INFO, "BLE Host Task Started");
|
||||
/* This function will return only when nimble_port_stop() is executed */
|
||||
nimble_port_run();
|
||||
|
||||
nimble_port_freertos_deinit();
|
||||
}
|
||||
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
/* Initialize NVS — it is used to store PHY calibration data */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
nimble_port_init();
|
||||
|
||||
ble_hs_cfg.sync_cb = on_sync;
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
#else
|
||||
peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
#endif
|
||||
ble_svc_gap_init();
|
||||
ble_svc_gatt_init();
|
||||
ble_svc_ans_init();
|
||||
|
||||
ble_gatts_count_cfg(gatt_svr_svcs);
|
||||
ble_gatts_add_svcs(gatt_svr_svcs);
|
||||
|
||||
nimble_port_freertos_init(ble_hs_task);
|
||||
}
|
||||
@@ -698,9 +698,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-htp-cent");
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,46 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4000
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -572,9 +572,13 @@ app_main(void)
|
||||
#endif
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("blecent-l2coc");
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM=1
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=30
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=512
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,50 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM=1
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=30
|
||||
CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=512
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,49 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES=4
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -454,9 +454,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM, BLE_PEER_MAX_NUM);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
/* Set the default device name. We will act as both central and peripheral. */
|
||||
rc = ble_svc_gap_device_name_set("esp-ble-role-coex");
|
||||
assert(rc == 0);
|
||||
|
||||
@@ -22,7 +22,6 @@ static void start_scan(void);
|
||||
static struct ble_hs_adv_fields fields;
|
||||
static bool synced = false;
|
||||
|
||||
uint8_t rsp_slot_idx = 0;
|
||||
static int
|
||||
gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
@@ -57,12 +56,11 @@ gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
event->periodic_report.event_counter,
|
||||
event->periodic_report.subevent);
|
||||
|
||||
rsp_slot_idx += 1;
|
||||
struct ble_gap_periodic_adv_response_params param = {
|
||||
.request_event = event->periodic_report.event_counter,
|
||||
.request_subevent = event->periodic_report.subevent,
|
||||
.response_subevent = event->periodic_report.subevent,
|
||||
.response_slot = rsp_slot_idx,
|
||||
.response_slot = 2,
|
||||
};
|
||||
|
||||
struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0);
|
||||
@@ -129,8 +127,9 @@ static int
|
||||
create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
|
||||
{
|
||||
int rc;
|
||||
struct ble_gap_periodic_sync_params params;
|
||||
struct ble_gap_periodic_sync_params params = {0};
|
||||
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.skip = 0;
|
||||
params.sync_timeout = 4000;
|
||||
params.reports_disabled = 0;
|
||||
@@ -159,9 +158,11 @@ start_scan(void)
|
||||
int rc;
|
||||
struct ble_gap_ext_disc_params disc_params;
|
||||
|
||||
|
||||
/* Perform a passive scan. I.e., don't send follow-up scan requests to
|
||||
* each advertiser.
|
||||
*/
|
||||
memset(&disc_params, 0, sizeof(disc_params));
|
||||
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
|
||||
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
|
||||
disc_params.passive = 1;
|
||||
@@ -182,23 +183,6 @@ on_reset(int reason)
|
||||
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
|
||||
}
|
||||
|
||||
/* Cnnot find `ble_single_xxxx()`, workaround */
|
||||
// static void
|
||||
// on_sync(void)
|
||||
// {
|
||||
// int ble_single_env_init(void);
|
||||
// int ble_single_init(void);
|
||||
|
||||
// int rc;
|
||||
|
||||
// rc = ble_single_env_init();
|
||||
// assert(!rc);
|
||||
// rc = ble_single_init();
|
||||
// assert(!rc);
|
||||
|
||||
// start_scan();
|
||||
// }
|
||||
|
||||
static void
|
||||
on_sync(void)
|
||||
{
|
||||
|
||||
@@ -185,8 +185,8 @@ static int
|
||||
create_periodic_sync(struct ble_gap_ext_disc_desc *disc)
|
||||
{
|
||||
int rc;
|
||||
struct ble_gap_periodic_sync_params params;
|
||||
|
||||
struct ble_gap_periodic_sync_params params = {0};
|
||||
memset(¶ms, 0, sizeof(params));
|
||||
params.skip = 0;
|
||||
params.sync_timeout = 4000;
|
||||
params.reports_disabled = 0;
|
||||
@@ -218,6 +218,7 @@ start_scan(void)
|
||||
/* Perform a passive scan. I.e., don't send follow-up scan requests to
|
||||
* each advertiser.
|
||||
*/
|
||||
memset(&disc_params, 0, sizeof(disc_params));
|
||||
disc_params.itvl = BLE_GAP_SCAN_ITVL_MS(600);
|
||||
disc_params.window = BLE_GAP_SCAN_ITVL_MS(300);
|
||||
disc_params.passive = 1;
|
||||
@@ -238,23 +239,6 @@ on_reset(int reason)
|
||||
ESP_LOGE(TAG, "Resetting state; reason=%d\n", reason);
|
||||
}
|
||||
|
||||
/* Cnnot find `ble_single_xxxx()`, workaround */
|
||||
// static void
|
||||
// on_sync(void)
|
||||
// {
|
||||
// int ble_single_env_init(void);
|
||||
// int ble_single_init(void);
|
||||
|
||||
// int rc;
|
||||
|
||||
// rc = ble_single_env_init();
|
||||
// assert(!rc);
|
||||
// rc = ble_single_init();
|
||||
// assert(!rc);
|
||||
|
||||
// start_scan();
|
||||
// }
|
||||
|
||||
static void
|
||||
on_sync(void)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_EXAMPLE_EXTENDED_ADV=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -203,9 +203,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble_periodic_sync");
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_EXAMPLE_EXTENDED_ADV=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -553,9 +553,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("blecent-phy");
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_BLE_GATT_BLOB_TRANSFER=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_EXT_ADV=y
|
||||
CONFIG_BT_NIMBLE_BLE_GATT_BLOB_TRANSFER=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -722,9 +722,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-prox-cent");
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -488,9 +488,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-ble-spp-client");
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=3
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,45 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=3
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -131,6 +131,35 @@ GAP procedure initiated: terminate connection; conn_handle=0 hci_reason=19
|
||||
disconnect; reason=534
|
||||
```
|
||||
|
||||
The following configuration flags can be adjusted to significantly reduce RAM usage in your ESP-IDF project while retaining basic BLE functionality.
|
||||
----------------------------------------------------------------------------------------------
|
||||
| Config Option || Old → New Value || RAM Saved (Bytes) |
|
||||
|--------------------------------------------------||------------------||--------------------|
|
||||
| CONFIG_BT_NIMBLE_SM_SC || y → n || 2040 |
|
||||
| CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION || y → n || 32 |
|
||||
| CONFIG_BT_NIMBLE_GATT_MAX_PROCS || 4 → 2 || 112 |
|
||||
| CONFIG_BT_NIMBLE_MAX_CONNECTIONS || 3 → 1 || 480 |
|
||||
| CONFIG_BT_NIMBLE_MAX_BONDS || 3 → 1 || 448 |
|
||||
| CONFIG_BT_NIMBLE_MAX_CCCDS || 8 → 1 || 112 |
|
||||
| CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT || y → n || 256 |
|
||||
| CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT || 30 → 15 || 240 |
|
||||
| CONFIG_BT_NIMBLE_SECURITY_ENABLE || y → n || 2072 |
|
||||
| CONFIG_SPI_FLASH_ROM_IMPL || n → y || 9804 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP || y → n || 0 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP || y → n || 140 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_GD_CHIP || y → n || 648 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP || y → n || 8 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP || y → n || 140 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_TH_CHIP || y → n || 136 |
|
||||
| CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE || y → n || 704 |
|
||||
| CONFIG_VFS_SUPPORT_TERMIOS || y → n || 424 |
|
||||
| CONFIG_VFS_SUPPORT_IO || y → n || 2008 |
|
||||
| CONFIG_COMPILER_OPTIMIZATION_SIZE || n → y || 8408 |
|
||||
| CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE || n → y || 5896 |
|
||||
| CONFIG_ESP_COEX_SW_COEXIST_ENABLE || y → n || 896 |
|
||||
| ESP_TASK_WDT_EN || y → n || 528 |
|
||||
| CONFIG_LOG_DEFAULT_LEVEL_NONE || n → y || 2592 |
|
||||
----------------------------------------------------------------------------------------------
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
|
||||
@@ -709,7 +709,9 @@ static void blecent_power_control(uint16_t conn_handle)
|
||||
static int
|
||||
blecent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
struct ble_gap_conn_desc desc;
|
||||
#endif
|
||||
struct ble_hs_adv_fields fields;
|
||||
#if MYNEWT_VAL(BLE_HCI_VS)
|
||||
#if MYNEWT_VAL(BLE_POWER_CONTROL)
|
||||
@@ -732,7 +734,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
/* Try to connect to the advertiser if it looks interesting. */
|
||||
blecent_connect_if_interesting(&event->disc);
|
||||
return 0;
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
/* A new connection was established or a connection attempt failed. */
|
||||
if (event->connect.status == 0) {
|
||||
@@ -966,6 +968,8 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -1041,7 +1045,6 @@ static void stack_init_deinit(void)
|
||||
void
|
||||
app_main(void)
|
||||
{
|
||||
int rc;
|
||||
/* Initialize NVS — it is used to store PHY calibration data */
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
@@ -1061,6 +1064,8 @@ app_main(void)
|
||||
ble_hs_cfg.sync_cb = blecent_on_sync;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
int rc;
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
@@ -1069,11 +1074,13 @@ app_main(void)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
int m;
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-blecent");
|
||||
assert(rc == 0);
|
||||
m = ble_svc_gap_device_name_set("nimble-blecent");
|
||||
assert(m == 0);
|
||||
#endif
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=n
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=n
|
||||
@@ -0,0 +1,11 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=n
|
||||
CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,47 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -0,0 +1,48 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4000
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -92,6 +92,35 @@ Notification sent successfully
|
||||
## Note
|
||||
* NVS support is not yet integrated to bonding. So, for now, bonding is not persistent across reboot.
|
||||
|
||||
The following configuration flags can be adjusted to significantly reduce RAM usage in your ESP-IDF project while retaining basic BLE functionality.
|
||||
----------------------------------------------------------------------------------------------
|
||||
| Config Option || Old → New Value || RAM Saved (Bytes) |
|
||||
|--------------------------------------------------||------------------||--------------------|
|
||||
| CONFIG_BT_NIMBLE_SM_SC || y → n || 2016 |
|
||||
| CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION || y → n || 32 |
|
||||
| CONFIG_BT_NIMBLE_GATT_MAX_PROCS || 4 → 2 || 112 |
|
||||
| CONFIG_BT_NIMBLE_MAX_CONNECTIONS || 3 → 1 || 480 |
|
||||
| CONFIG_BT_NIMBLE_MAX_BONDS || 3 → 1 || 448 |
|
||||
| CONFIG_BT_NIMBLE_MAX_CCCDS || 8 → 1 || 112 |
|
||||
| CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT || y → n || 256 |
|
||||
| CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT || 30 → 15 || 240 |
|
||||
| CONFIG_BT_NIMBLE_SECURITY_ENABLE || y → n || 2048 |
|
||||
| CONFIG_SPI_FLASH_ROM_IMPL || n → y || 9804 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP || y → n || 8 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP || y → n || 132 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_GD_CHIP || y → n || 640 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP || y → n || 0 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP || y → n || 132 |
|
||||
| CONFIG_SPI_FLASH_SUPPORT_TH_CHIP || y → n || 128 |
|
||||
| CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE || y → n || 696 |
|
||||
| CONFIG_VFS_SUPPORT_TERMIOS || y → n || 424 |
|
||||
| CONFIG_VFS_SUPPORT_IO || y → n || 3000 |
|
||||
| CONFIG_COMPILER_OPTIMIZATION_SIZE || n → y || 8912 |
|
||||
| CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE || n → y || 8456 |
|
||||
| CONFIG_ESP_COEX_SW_COEXIST_ENABLE || y → n || 896 |
|
||||
| CONFIG_LOG_DEFAULT_LEVEL_NONE || n → y || 2568 |
|
||||
----------------------------------------------------------------------------------------------
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
|
||||
|
||||
@@ -52,6 +52,7 @@ static uint16_t bearers;
|
||||
|
||||
void ble_store_config_init(void);
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
/**
|
||||
* Logs information about a connection to the console.
|
||||
*/
|
||||
@@ -78,6 +79,7 @@ bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
|
||||
desc->sec_state.authenticated,
|
||||
desc->sec_state.bonded);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_EXAMPLE_EXTENDED_ADV
|
||||
/**
|
||||
@@ -148,7 +150,9 @@ bleprph_advertise(void)
|
||||
{
|
||||
struct ble_gap_adv_params adv_params;
|
||||
struct ble_hs_adv_fields fields;
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
const char *name;
|
||||
#endif
|
||||
int rc;
|
||||
|
||||
/**
|
||||
@@ -175,10 +179,12 @@ bleprph_advertise(void)
|
||||
fields.tx_pwr_lvl_is_present = 1;
|
||||
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
name = ble_svc_gap_device_name();
|
||||
fields.name = (uint8_t *)name;
|
||||
fields.name_len = strlen(name);
|
||||
fields.name_is_complete = 1;
|
||||
#endif
|
||||
|
||||
fields.uuids16 = (ble_uuid16_t[]) {
|
||||
BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID)
|
||||
@@ -236,10 +242,14 @@ static void bleprph_power_control(uint16_t conn_handle)
|
||||
static int
|
||||
bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
struct ble_gap_conn_desc desc;
|
||||
int rc;
|
||||
#endif
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
/* A new connection was established or a connection attempt failed. */
|
||||
MODLOG_DFLT(INFO, "connection %s; status=%d ",
|
||||
@@ -463,9 +473,9 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg)
|
||||
event->subrate_change.status,
|
||||
event->subrate_change.subrate_factor);
|
||||
return 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -594,9 +604,11 @@ app_main(void)
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_NIMBLE_GAP_SERVICE
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("nimble-bleprph");
|
||||
assert(rc == 0);
|
||||
#endif
|
||||
|
||||
/* XXX Need to have template for store */
|
||||
ble_store_config_init();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=n
|
||||
CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=y
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=y
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
||||
@@ -0,0 +1,10 @@
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
CONFIG_BT_NIMBLE_ROLE_CENTRAL=n
|
||||
CONFIG_BT_NIMBLE_ROLE_BROADCASTER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_OBSERVER=n
|
||||
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL=y
|
||||
@@ -0,0 +1,45 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_ROM_IMPL=y
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "esp_central.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
static void *peer_svc_mem;
|
||||
static struct os_mempool peer_svc_pool;
|
||||
|
||||
@@ -601,13 +602,16 @@ peer_disc_incs(struct peer *peer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
svc = peer->cur_svc;
|
||||
rc = ble_gattc_find_inc_svcs(peer->conn_handle,
|
||||
svc->svc.start_handle,
|
||||
svc->svc.end_handle,
|
||||
peer_inc_disced, peer);
|
||||
if (rc != 0) {
|
||||
if (svc != NULL && !peer_svc_is_empty(svc)) {
|
||||
rc = ble_gattc_find_inc_svcs(peer->conn_handle,
|
||||
svc->svc.start_handle,
|
||||
svc->svc.end_handle,
|
||||
peer_inc_disced, peer);
|
||||
if (rc != 0) {
|
||||
peer_disc_chrs(peer);
|
||||
}
|
||||
} else {
|
||||
peer_disc_chrs(peer);
|
||||
}
|
||||
}
|
||||
@@ -1089,3 +1093,4 @@ err:
|
||||
peer_free_mem();
|
||||
return rc;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
# Override some defaults so BT stack is enabled
|
||||
# in this example
|
||||
|
||||
#
|
||||
# BT config
|
||||
#
|
||||
CONFIG_BT_ENABLED=y
|
||||
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
|
||||
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
|
||||
CONFIG_BTDM_CTRL_MODE_BTDM=n
|
||||
CONFIG_BT_BLUEDROID_ENABLED=n
|
||||
CONFIG_BT_NIMBLE_ENABLED=y
|
||||
|
||||
# Enable support for power management
|
||||
CONFIG_PM_ENABLE=y
|
||||
# Enable tickless idle mode
|
||||
CONFIG_FREERTOS_USE_TICKLESS_IDLE=y
|
||||
# Set the tick rate at which FreeRTOS does pre-emptive context switching.
|
||||
CONFIG_FREERTOS_HZ=1000
|
||||
# Minimum number of ticks to enter sleep mode for
|
||||
CONFIG_FREERTOS_IDLE_TIME_BEFORE_SLEEP=3
|
||||
CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4000
|
||||
|
||||
CONFIG_BT_NIMBLE_SM_SC=n
|
||||
CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION=n
|
||||
CONFIG_BT_NIMBLE_GATT_MAX_PROCS=2
|
||||
CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1
|
||||
CONFIG_BT_NIMBLE_MAX_BONDS=1
|
||||
CONFIG_BT_NIMBLE_MAX_CCCDS=1
|
||||
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
|
||||
CONFIG_BT_NIMBLE_TRANSPORT_EVT_COUNT=15
|
||||
|
||||
#Uncomment below, if security needs to be disabled
|
||||
#CONFIG_BT_NIMBLE_SECURITY_ENABLE=n
|
||||
|
||||
CONFIG_SPI_FLASH_SUPPORT_ISSI_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_MXIC_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_GD_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_WINBOND_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_BOYA_CHIP=n
|
||||
CONFIG_SPI_FLASH_SUPPORT_TH_CHIP=n
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
|
||||
CONFIG_VFS_SUPPORT_TERMIOS=n
|
||||
CONFIG_VFS_SUPPORT_IO=n
|
||||
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE=y
|
||||
|
||||
CONFIG_ESP_COEX_SW_COEXIST_ENABLE=n
|
||||
|
||||
CONFIG_ESP_TASK_WDT_EN=n
|
||||
|
||||
#Uncomment below, if logging needs to be disabled
|
||||
#CONFIG_LOG_DEFAULT_LEVEL_NONE=y
|
||||
#CONFIG_LOG_DEFAULT_LEVEL=0
|
||||
@@ -50,10 +50,21 @@ struct peer_chr {
|
||||
};
|
||||
SLIST_HEAD(peer_chr_list, peer_chr);
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
struct peer_incl_svc {
|
||||
SLIST_ENTRY(peer_incl_svc) next;
|
||||
struct ble_gatt_incl_svc svc;
|
||||
};
|
||||
SLIST_HEAD(peer_incl_svc_list, peer_incl_svc);
|
||||
#endif
|
||||
|
||||
struct peer_svc {
|
||||
SLIST_ENTRY(peer_svc) next;
|
||||
struct ble_gatt_svc svc;
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
struct peer_incl_svc_list incl_svc;
|
||||
#endif
|
||||
struct peer_chr_list chrs;
|
||||
};
|
||||
SLIST_HEAD(peer_svc_list, peer_svc);
|
||||
@@ -90,7 +101,11 @@ const struct peer_svc *
|
||||
peer_svc_find_uuid(const struct peer *peer, const ble_uuid_t *uuid);
|
||||
int peer_delete(uint16_t conn_handle);
|
||||
int peer_add(uint16_t conn_handle);
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
int peer_init(int max_peers, int max_svcs, int max_incl_svcs, int max_chrs, int max_dscs);
|
||||
#else
|
||||
int peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs);
|
||||
#endif
|
||||
struct peer *
|
||||
peer_find(uint16_t conn_handle);
|
||||
/* Console */
|
||||
|
||||
@@ -938,9 +938,13 @@ app_main(void)
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
/* Initialize data structures to track connected peers. */
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
#else
|
||||
rc = peer_init(MYNEWT_VAL(BLE_MAX_CONNECTIONS), 64, 64, 64);
|
||||
assert(rc == 0);
|
||||
|
||||
#endif
|
||||
/* Set the default device name. */
|
||||
rc = ble_svc_gap_device_name_set("gattc-throughput");
|
||||
assert(rc == 0);
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
static void *peer_svc_mem;
|
||||
static struct os_mempool peer_svc_pool;
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
static void *peer_incl_svc_mem;
|
||||
static struct os_mempool peer_incl_svc_pool;
|
||||
#endif
|
||||
|
||||
static void *peer_chr_mem;
|
||||
static struct os_mempool peer_chr_pool;
|
||||
|
||||
@@ -44,7 +49,13 @@ static int
|
||||
peer_dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
|
||||
void *arg);
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
static int
|
||||
peer_inc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_incl_svc *service, void *arg);
|
||||
static void
|
||||
peer_disc_incs(struct peer *peer);
|
||||
#endif
|
||||
struct peer *
|
||||
peer_find(uint16_t conn_handle)
|
||||
{
|
||||
@@ -420,6 +431,193 @@ peer_disc_chrs(struct peer *peer)
|
||||
peer_disc_dscs(peer);
|
||||
}
|
||||
|
||||
#if (MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES))
|
||||
static struct peer_incl_svc *
|
||||
peer_incl_svc_find_prev(const struct peer_svc *svc, uint16_t incl_svc_handle)
|
||||
{
|
||||
struct peer_incl_svc *prev;
|
||||
struct peer_incl_svc *incl_svc;
|
||||
|
||||
prev = NULL;
|
||||
SLIST_FOREACH(incl_svc, &svc->incl_svc, next) {
|
||||
if (incl_svc->svc.handle >= incl_svc_handle) {
|
||||
break;
|
||||
}
|
||||
|
||||
prev = incl_svc;
|
||||
}
|
||||
|
||||
return prev;
|
||||
}
|
||||
|
||||
static struct peer_incl_svc *
|
||||
peer_incl_svc_find(const struct peer_svc *svc, uint16_t incl_svc_handle,
|
||||
struct peer_incl_svc **out_prev)
|
||||
{
|
||||
struct peer_incl_svc *prev;
|
||||
struct peer_incl_svc *incl_svc;
|
||||
|
||||
prev = peer_incl_svc_find_prev(svc, incl_svc_handle);
|
||||
if (prev == NULL) {
|
||||
incl_svc = SLIST_FIRST(&svc->incl_svc);
|
||||
} else {
|
||||
incl_svc = SLIST_NEXT(prev, next);
|
||||
}
|
||||
|
||||
if (incl_svc != NULL && incl_svc->svc.handle != incl_svc_handle) {
|
||||
incl_svc = NULL;
|
||||
}
|
||||
|
||||
if (out_prev != NULL) {
|
||||
*out_prev = prev;
|
||||
}
|
||||
return incl_svc;
|
||||
}
|
||||
|
||||
static void
|
||||
peer_incl_svc_delete(struct peer_incl_svc *incl_svc)
|
||||
{
|
||||
os_memblock_put(&peer_incl_svc_pool, incl_svc);
|
||||
}
|
||||
|
||||
static int
|
||||
peer_inc_add(struct peer *peer, uint16_t svc_start_handle,
|
||||
const struct ble_gatt_incl_svc *gatt_incl_svc)
|
||||
{
|
||||
struct peer_incl_svc *incl_svc;
|
||||
struct peer_incl_svc *incl_svc_prev;
|
||||
struct peer_svc *cur_svc;
|
||||
struct peer_svc *svc;
|
||||
struct peer_svc *prev;
|
||||
|
||||
svc = peer_svc_find(peer, gatt_incl_svc->start_handle, &prev);
|
||||
|
||||
if (!svc) {
|
||||
/* secondary service */
|
||||
svc = os_memblock_get(&peer_svc_pool);
|
||||
if (svc == NULL) {
|
||||
/* out of memory */
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
memset(svc, 0, sizeof *svc);
|
||||
svc->svc.start_handle = gatt_incl_svc->start_handle;
|
||||
svc->svc.end_handle = gatt_incl_svc->end_handle;
|
||||
memcpy(&svc->svc.uuid, &gatt_incl_svc->uuid, sizeof(ble_uuid_any_t));
|
||||
|
||||
SLIST_INIT(&svc->chrs);
|
||||
SLIST_INIT(&svc->incl_svc);
|
||||
|
||||
if (prev == NULL) {
|
||||
SLIST_INSERT_HEAD(&peer->svcs, svc, next);
|
||||
} else {
|
||||
SLIST_INSERT_AFTER(prev, svc, next);
|
||||
}
|
||||
}
|
||||
|
||||
/* Including the services into inlucding list */
|
||||
|
||||
cur_svc = peer_svc_find_range(peer, gatt_incl_svc->handle);
|
||||
|
||||
if (cur_svc == NULL) {
|
||||
/* Can't find service for discovered included service; this shouldn't
|
||||
* happen.
|
||||
*/
|
||||
assert(0);
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
incl_svc = peer_incl_svc_find(cur_svc, gatt_incl_svc->handle, &incl_svc_prev);
|
||||
if (incl_svc != NULL) {
|
||||
/* Already discovered */
|
||||
return 0;
|
||||
}
|
||||
|
||||
incl_svc = os_memblock_get(&peer_incl_svc_pool);
|
||||
if (incl_svc == NULL) {
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
incl_svc->svc = *gatt_incl_svc;
|
||||
|
||||
if (incl_svc_prev == NULL) {
|
||||
SLIST_INSERT_HEAD(&cur_svc->incl_svc, incl_svc, next);
|
||||
} else {
|
||||
SLIST_INSERT_AFTER(incl_svc_prev, incl_svc, next);
|
||||
}
|
||||
|
||||
BLE_HS_LOG(DEBUG, "Inc Service added with handle = %d", gatt_incl_svc->handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
peer_inc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_incl_svc *service, void *arg)
|
||||
{
|
||||
struct peer *peer;
|
||||
int rc;
|
||||
|
||||
peer = arg;
|
||||
assert(peer->conn_handle == conn_handle);
|
||||
|
||||
switch (error->status) {
|
||||
case 0:
|
||||
rc = peer_inc_add(peer, peer->cur_svc->svc.start_handle, service);
|
||||
break;
|
||||
|
||||
case BLE_HS_EDONE:
|
||||
peer_disc_incs(peer);
|
||||
rc = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = error->status;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc != 0) {
|
||||
/* Error; abort discovery. */
|
||||
peer_disc_complete(peer, rc);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
peer_disc_incs(struct peer *peer)
|
||||
{
|
||||
struct peer_svc *svc;
|
||||
int rc;
|
||||
|
||||
if (peer->cur_svc == NULL) {
|
||||
peer->cur_svc = SLIST_FIRST(&peer->svcs);
|
||||
} else {
|
||||
peer->cur_svc = SLIST_NEXT(peer->cur_svc, next);
|
||||
if (peer->cur_svc == NULL) {
|
||||
if (peer->disc_prev_chr_val > 0) {
|
||||
peer_disc_chrs(peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
svc = peer->cur_svc;
|
||||
if (svc != NULL && !peer_svc_is_empty(svc)) {
|
||||
rc = ble_gattc_find_inc_svcs(peer->conn_handle,
|
||||
svc->svc.start_handle,
|
||||
svc->svc.end_handle,
|
||||
peer_inc_disced, peer);
|
||||
if (rc != 0) {
|
||||
peer_disc_chrs(peer);
|
||||
}
|
||||
} else {
|
||||
peer_disc_chrs(peer);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int
|
||||
peer_svc_is_empty(const struct peer_svc *svc)
|
||||
{
|
||||
@@ -576,6 +774,14 @@ peer_svc_delete(struct peer_svc *svc)
|
||||
{
|
||||
struct peer_chr *chr;
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
struct peer_incl_svc *incl_svc;
|
||||
|
||||
while ((incl_svc = SLIST_FIRST(&svc->incl_svc)) != NULL) {
|
||||
SLIST_REMOVE_HEAD(&svc->incl_svc, next);
|
||||
peer_incl_svc_delete(incl_svc);
|
||||
}
|
||||
#endif
|
||||
while ((chr = SLIST_FIRST(&svc->chrs)) != NULL) {
|
||||
SLIST_REMOVE_HEAD(&svc->chrs, next);
|
||||
peer_chr_delete(chr);
|
||||
@@ -600,10 +806,16 @@ peer_svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
break;
|
||||
|
||||
case BLE_HS_EDONE:
|
||||
/* All services discovered; start discovering characteristics. */
|
||||
/* All services discovered; start discovering incs.*/
|
||||
#if (MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES))
|
||||
peer->cur_svc = NULL;
|
||||
peer_disc_incs(peer);
|
||||
#else
|
||||
/* All services discovered; start discovering characteristics. */
|
||||
if (peer->disc_prev_chr_val > 0) {
|
||||
peer_disc_chrs(peer);
|
||||
}
|
||||
#endif
|
||||
rc = 0;
|
||||
break;
|
||||
|
||||
@@ -711,6 +923,11 @@ peer_free_mem(void)
|
||||
free(peer_svc_mem);
|
||||
peer_svc_mem = NULL;
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
free(peer_incl_svc_mem);
|
||||
peer_incl_svc_mem = NULL;
|
||||
#endif
|
||||
|
||||
free(peer_chr_mem);
|
||||
peer_chr_mem = NULL;
|
||||
|
||||
@@ -718,8 +935,13 @@ peer_free_mem(void)
|
||||
peer_dsc_mem = NULL;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
int
|
||||
peer_init(int max_peers, int max_svcs, int max_incl_svcs, int max_chrs, int max_dscs)
|
||||
#else
|
||||
int
|
||||
peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs)
|
||||
#endif
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -756,6 +978,23 @@ peer_init(int max_peers, int max_svcs, int max_chrs, int max_dscs)
|
||||
goto err;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_INCL_SVC_DISCOVERY) || MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
peer_incl_svc_mem = malloc(
|
||||
OS_MEMPOOL_BYTES(max_incl_svcs, sizeof(struct peer_incl_svc)));
|
||||
|
||||
if (peer_incl_svc_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
rc = os_mempool_init(&peer_incl_svc_pool, max_incl_svcs,
|
||||
sizeof(struct peer_incl_svc), peer_incl_svc_mem,
|
||||
"peer_incl_svc_pool");
|
||||
if (rc != 0) {
|
||||
rc = BLE_HS_EOS;
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
peer_chr_mem = malloc(
|
||||
OS_MEMPOOL_BYTES(max_chrs, sizeof (struct peer_chr)));
|
||||
if (peer_chr_mem == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user