Skip to content

Commit 2e1ba1c

Browse files
committed
Update nimble core to esp-nimble commit #e3cbdc0
* Commit #3fa3334 support hci log for nimble removed
1 parent cf0b3d0 commit 2e1ba1c

29 files changed

+843
-289
lines changed

src/nimble/esp_port/port/include/esp_nimble_cfg.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,10 @@
420420
#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL)
421421
#endif
422422

423+
#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT_VAR
424+
#define MYNEWT_VAL_BLE_GATT_READ_MULT_VAR (MYNEWT_VAL_BLE_ROLE_CENTRAL)
425+
#endif
426+
423427
#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID
424428
#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
425429
#endif

src/nimble/nimble/host/include/host/ble_esp_gap.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,28 @@ int ble_gap_wl_read_size(uint8_t *size);
112112
*/
113113
int ble_gap_host_check_status(void);
114114

115+
/**
116+
* This API is called to get local used address and address type.
117+
*
118+
* @param addr On success, locally used address will be stored here.
119+
*
120+
* @return 0 on success; nonzero on failure.
121+
*/
122+
int ble_gap_get_local_used_addr(ble_addr_t *addr);
123+
124+
/**
125+
* This API is called to get ADV data for a specific type.
126+
127+
*
128+
* @param adv_data Pointer of ADV data (unsigned 8 bit integer) which to be resolved.
129+
* @param adv_type Finding ADV data type.
130+
* @param adv_data_len Total length of Advertising data.
131+
* @param length Return the length of ADV data not including type.
132+
*
133+
* @return Pointer (unsigned 8 bit integer) of type specific ADV data.
134+
*/
135+
uint8_t* ble_resolve_adv_data(const uint8_t *adv_data, uint8_t adv_type, uint8_t adv_data_len , uint8_t * length);
136+
115137
#if MYNEWT_VAL(BLE_HCI_VS)
116138
#if MYNEWT_VAL(BLE_POWER_CONTROL)
117139

src/nimble/nimble/host/include/host/ble_gap.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct hci_conn_update;
158158
#define BLE_GAP_EVENT_REATTEMPT_COUNT 29
159159
#define BLE_GAP_EVENT_AUTHORIZE 30
160160
#define BLE_GAP_EVENT_TEST_UPDATE 31
161-
161+
#define BLE_GAP_EVENT_DATA_LEN_CHG 32
162162

163163
/* DTM events */
164164
#define BLE_GAP_DTM_TX_START_EVT 0
@@ -1174,8 +1174,31 @@ struct ble_gap_event {
11741174
* Valid only for BLE_GAP_DTM_END_EVT
11751175
* shall be 0 for a transmitter.
11761176
*/
1177-
uint8_t num_pkt;
1177+
uint16_t num_pkt;
11781178
} dtm_state;
1179+
1180+
/**
1181+
* Represent an event for LE Data length change
1182+
*
1183+
* Valid for the following event types:
1184+
* o BLE_GAP_EVENT_DATA_LEN_CHG
1185+
*/
1186+
struct {
1187+
/* Connection handle */
1188+
uint16_t conn_handle;
1189+
1190+
/* Max Tx Payload octotes */
1191+
uint16_t max_tx_octets;
1192+
1193+
/* Max Tx Time */
1194+
uint16_t max_tx_time;
1195+
1196+
/* Max Rx payload octet */
1197+
uint16_t max_rx_octets;
1198+
1199+
/* Max Rx Time */
1200+
uint16_t max_rx_time;
1201+
} data_len_chg;
11791202
};
11801203
};
11811204

src/nimble/nimble/host/include/host/ble_gatt.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ typedef int ble_gatt_attr_fn(uint16_t conn_handle,
329329
struct ble_gatt_attr *attr,
330330
void *arg);
331331

332+
/**
333+
* The host will free the attribute mbuf automatically after the callback is
334+
* executed. The application can take ownership of the mbuf and prevent it
335+
* from being freed by assigning NULL to attr->om.
336+
*/
337+
typedef int ble_gatt_attr_mult_fn(uint16_t conn_handle,
338+
const struct ble_gatt_error *error,
339+
struct ble_gatt_attr *attrs,
340+
uint8_t num_attrs,
341+
void *arg);
342+
332343
/**
333344
* The host will free the attribute mbufs automatically after the callback is
334345
* executed. The application can take ownership of the mbufs and prevent them
@@ -545,6 +556,10 @@ int ble_gattc_read_mult(uint16_t conn_handle, const uint16_t *handles,
545556
uint8_t num_handles, ble_gatt_attr_fn *cb,
546557
void *cb_arg);
547558

559+
int ble_gattc_read_mult_var(uint16_t conn_handle, const uint16_t *handles,
560+
uint8_t num_handles, ble_gatt_attr_mult_fn *cb,
561+
void *cb_arg);
562+
548563
/**
549564
* Initiates GATT procedure: Write Without Response. This function consumes
550565
* the supplied mbuf regardless of the outcome.
@@ -882,7 +897,7 @@ struct ble_gatt_cpfd {
882897
uint16_t unit;
883898

884899
/** The name space of the description. */
885-
uint8_t namespace_;
900+
uint8_t name_space;
886901

887902
/** The description of this characteristic. Depends on name space. */
888903
uint16_t description;

src/nimble/nimble/host/include/host/ble_hs_pvcy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void ble_hs_resolv_deinit(void);
6969
#endif
7070

7171
int ble_hs_pvcy_set_resolve_enabled(int enable);
72+
void ble_hs_set_rpa_timeout(uint16_t timeout);
7273

7374
#ifdef __cplusplus
7475
}

src/nimble/nimble/host/include/host/ble_store.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ struct ble_store_key_sec {
7777
*/
7878
struct ble_store_value_sec {
7979
ble_addr_t peer_addr;
80+
uint16_t bond_count;
8081

8182
uint8_t key_size;
8283
uint16_t ediv;

src/nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ struct ble_hs_cfg;
3636
#if MYNEWT_VAL(BLE_GATT_CACHING)
3737
#define BLE_SVC_GATT_CHR_DATABASE_HASH_UUID16 0x2b2a
3838

39-
uint16_t ble_svc_gatt_changed_handle();
40-
uint16_t ble_svc_gatt_hash_handle();
41-
uint16_t ble_svc_gatt_csf_handle();
42-
uint8_t ble_svc_gatt_get_csfs();
39+
uint16_t ble_svc_gatt_changed_handle(void);
40+
uint16_t ble_svc_gatt_hash_handle(void);
41+
uint16_t ble_svc_gatt_csf_handle(void);
42+
uint8_t ble_svc_gatt_get_csfs(void);
4343
#endif
4444

4545
uint8_t ble_svc_gatt_get_local_cl_supported_feat(void);

src/nimble/nimble/host/src/ble_att.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static const struct ble_att_rx_dispatch_entry ble_att_rx_dispatch[] = {
7070
{ BLE_ATT_OP_INDICATE_REQ, ble_att_svr_rx_indicate },
7171
{ BLE_ATT_OP_INDICATE_RSP, ble_att_clt_rx_indicate },
7272
{ BLE_ATT_OP_READ_MULT_VAR_REQ, ble_att_svr_rx_read_mult_var },
73+
{ BLE_ATT_OP_READ_MULT_VAR_RSP, ble_att_clt_rx_read_mult_var },
7374
{ BLE_ATT_OP_WRITE_CMD, ble_att_svr_rx_write_no_rsp },
7475
#ifdef ESP_PLATFORM
7576
{ BLE_ATT_OP_SIGNED_WRITE_CMD, ble_att_svr_rx_signed_write },

src/nimble/nimble/host/src/ble_att_clt.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom)
537537
*****************************************************************************/
538538
int
539539
ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *handles,
540-
int num_handles)
540+
int num_handles, bool variable)
541541
{
542542
#if !NIMBLE_BLE_ATT_CLT_READ_MULT
543543
return BLE_HS_ENOTSUP;
@@ -546,12 +546,15 @@ ble_att_clt_tx_read_mult(uint16_t conn_handle, const uint16_t *handles,
546546
struct ble_att_read_mult_req *req;
547547
struct os_mbuf *txom;
548548
int i;
549+
uint8_t op;
549550

550551
if (num_handles < 1) {
551552
return BLE_HS_EINVAL;
552553
}
553554

554-
req = ble_att_cmd_get(BLE_ATT_OP_READ_MULT_REQ,
555+
op = variable ? BLE_ATT_OP_READ_MULT_VAR_REQ : BLE_ATT_OP_READ_MULT_REQ;
556+
557+
req = ble_att_cmd_get(op,
555558
sizeof(req->handles[0]) * num_handles,
556559
&txom);
557560
if (req == NULL) {
@@ -573,7 +576,19 @@ ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom)
573576
#endif
574577

575578
/* Pass the Attribute Value field to GATT. */
576-
ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom);
579+
ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom, false);
580+
return 0;
581+
}
582+
583+
int
584+
ble_att_clt_rx_read_mult_var(uint16_t conn_handle, struct os_mbuf **rxom)
585+
{
586+
#if !NIMBLE_BLE_ATT_CLT_READ_MULT_VAR
587+
return BLE_HS_ENOTSUP;
588+
#endif
589+
590+
/* Pass the Attribute Value field to GATT. */
591+
ble_gattc_rx_read_mult_rsp(conn_handle, 0, rxom, true);
577592
return 0;
578593
}
579594

@@ -765,6 +780,7 @@ ble_att_clt_tx_signed_write_cmd(uint16_t conn_handle, uint16_t handle, uint8_t *
765780
struct os_mbuf *txom2;
766781
uint8_t cmac[16];
767782
uint8_t *message = NULL;
783+
uint8_t len;
768784
int rc;
769785
int i;
770786

@@ -781,27 +797,37 @@ ble_att_clt_tx_signed_write_cmd(uint16_t conn_handle, uint16_t handle, uint8_t *
781797
}
782798
cmd->handle = htole16(handle);
783799

784-
/* Message to be signed is message||sign_counter,
800+
/* Message to be signed is opcode||handle||message||sign_counter,
785801
* where || represents concatenation
786802
*/
787-
message = nimble_platform_mem_malloc(OS_MBUF_PKTLEN(txom) + sizeof(counter));
788-
rc = os_mbuf_copydata(txom, 0, OS_MBUF_PKTLEN(txom), message);
803+
len = BLE_ATT_SIGNED_WRITE_DATA_OFFSET + OS_MBUF_PKTLEN(txom) + sizeof(counter);
804+
message = nimble_platform_mem_malloc(len);
805+
806+
/** Copying opcode and handle */
807+
rc = os_mbuf_copydata(txom2, 0, BLE_ATT_SIGNED_WRITE_DATA_OFFSET, message);
808+
if (rc != 0) {
809+
goto err;
810+
}
811+
812+
/** Copying message */
813+
rc = os_mbuf_copydata(txom, 0, OS_MBUF_PKTLEN(txom), &message[BLE_ATT_SIGNED_WRITE_DATA_OFFSET]);
789814
if (rc != 0) {
790815
goto err;
791816
}
792-
memcpy(&message[OS_MBUF_PKTLEN(txom)], &counter, sizeof(counter));
793817

818+
/** Copying sign counter */
819+
memcpy(&message[BLE_ATT_SIGNED_WRITE_DATA_OFFSET + OS_MBUF_PKTLEN(txom)], &counter, sizeof(counter));
820+
794821
/* ble_sm_alg_aes_cmac takes data in little-endian format,
795822
* so converting it to LE.
796823
*/
797-
swap_in_place(message, OS_MBUF_PKTLEN(txom) + sizeof(counter));
824+
swap_in_place(message, len);
798825

799826
/* Getting the CMAC (Cipher-based Message Authentication Code)
800827
* for the message using our CSRK for this connection.
801828
*/
802829
memset(cmac, 0, sizeof cmac);
803-
rc = ble_sm_alg_aes_cmac(csrk, message,
804-
OS_MBUF_PKTLEN(txom) + sizeof(counter), cmac);
830+
rc = ble_sm_alg_aes_cmac(csrk, message, len, cmac);
805831
if (rc != 0) {
806832
goto err;
807833
}

src/nimble/nimble/host/src/ble_att_priv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ int ble_att_clt_tx_read_blob(uint16_t conn_handle, uint16_t handle,
275275
uint16_t offset);
276276
int ble_att_clt_rx_read_blob(uint16_t conn_handle, struct os_mbuf **rxom);
277277
int ble_att_clt_tx_read_mult(uint16_t conn_handle,
278-
const uint16_t *handles, int num_handles);
278+
const uint16_t *handles, int num_handles, bool variable);
279279
int ble_att_clt_rx_read_mult(uint16_t conn_handle, struct os_mbuf **rxom);
280+
int ble_att_clt_rx_read_mult_var(uint16_t conn_handle, struct os_mbuf **rxom);
280281
int ble_att_clt_tx_read_type(uint16_t conn_handle, uint16_t start_handle,
281282
uint16_t end_handle, const ble_uuid_t *uuid);
282283
int ble_att_clt_rx_read_type(uint16_t conn_handle, struct os_mbuf **rxom);

src/nimble/nimble/host/src/ble_att_svr.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ ble_att_svr_build_read_mult_rsp_var(uint16_t conn_handle,
18521852
int
18531853
ble_att_svr_rx_read_mult_var(uint16_t conn_handle, struct os_mbuf **rxom)
18541854
{
1855-
#if (!MYNEWT_VAL(BLE_ATT_SVR_READ_MULT) || (MYNEWT_VAL(BLE_VERSION) < 52))
1855+
#if !MYNEWT_VAL(BLE_ATT_SVR_READ_MULT)
18561856
return BLE_HS_ENOTSUP;
18571857
#endif
18581858

@@ -2358,7 +2358,9 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom)
23582358
uint16_t handle;
23592359
uint8_t sign[12];
23602360
uint8_t cmac[16];
2361+
uint8_t csrk[16];
23612362
uint8_t *message = NULL;
2363+
uint16_t len;
23622364
int rc;
23632365

23642366
rc = ble_gap_conn_find(conn_handle, &desc);
@@ -2388,9 +2390,6 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom)
23882390

23892391
handle = le16toh(req->handle);
23902392

2391-
/* Strip the request base from the front of the mbuf. */
2392-
os_mbuf_adj(*rxom, sizeof(*req));
2393-
23942393
os_mbuf_copydata(*rxom,
23952394
OS_MBUF_PKTLEN(*rxom) - (BLE_ATT_SIGNED_WRITE_CMD_BASE_SZ - BLE_ATT_SIGNED_WRITE_DATA_OFFSET),
23962395
BLE_ATT_SIGNED_WRITE_CMD_BASE_SZ - BLE_ATT_SIGNED_WRITE_DATA_OFFSET,
@@ -2400,16 +2399,22 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom)
24002399
os_mbuf_adj(*rxom, -(BLE_ATT_SIGNED_WRITE_CMD_BASE_SZ - BLE_ATT_SIGNED_WRITE_DATA_OFFSET));
24012400

24022401
/* Authentication procedure */
2403-
message = nimble_platform_mem_malloc(OS_MBUF_PKTLEN(*rxom) + sizeof(value_sec.sign_counter));
2404-
os_mbuf_copydata(*rxom, 0, OS_MBUF_PKTLEN(*rxom), message);
2405-
memcpy(&message[OS_MBUF_PKTLEN(*rxom)], &value_sec.sign_counter, sizeof(value_sec.sign_counter));
2402+
len = OS_MBUF_PKTLEN(*rxom) + sizeof(value_sec.sign_counter) + 1;
2403+
message = nimble_platform_mem_malloc(len);
2404+
2405+
message[0] = BLE_ATT_OP_SIGNED_WRITE_CMD;
2406+
os_mbuf_copydata(*rxom, 0, OS_MBUF_PKTLEN(*rxom), &message[1]);
2407+
memcpy(&message[1 + OS_MBUF_PKTLEN(*rxom)], &value_sec.sign_counter, sizeof(value_sec.sign_counter));
24062408

24072409
/* Converting message into little endian format */
2408-
swap_in_place(message, OS_MBUF_PKTLEN(*rxom) + sizeof(value_sec.sign_counter));
2410+
swap_in_place(message, len);
2411+
2412+
/* Converting CSRK into little endian format */
2413+
swap_buf(csrk, value_sec.csrk, 16);
24092414

24102415
/* Using AES-CMAC to get the CMAC from the message and CSRK of this device */
24112416
memset(cmac, 0, sizeof cmac);
2412-
rc = ble_sm_alg_aes_cmac(value_sec.csrk, message, OS_MBUF_PKTLEN(*rxom) + sizeof(value_sec.sign_counter), cmac);
2417+
rc = ble_sm_alg_aes_cmac(csrk, message, len, cmac);
24132418
if (rc != 0) {
24142419
goto err;
24152420
}
@@ -2435,6 +2440,9 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom)
24352440
goto err;
24362441
}
24372442

2443+
/* Strip the request base from the front of the mbuf. */
2444+
os_mbuf_adj(*rxom, sizeof(*req));
2445+
24382446
rc = ble_att_svr_write_handle(conn_handle, handle, 0, rxom, &att_err);
24392447
if (rc != 0) {
24402448
goto err;
@@ -2444,7 +2452,6 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, struct os_mbuf **rxom)
24442452
return 0;
24452453
err:
24462454
if(message != NULL) nimble_platform_mem_free(message);
2447-
ble_gap_terminate(conn_handle, BLE_ERR_AUTH_FAIL);
24482455
return rc;
24492456
}
24502457
#endif

0 commit comments

Comments
 (0)