Skip to content

Commit dd615f7

Browse files
Add direct advertising support.
To start direct connectable advertising on the cordio stack, the programmer should call the function DmConnAccept instead of the function DmAdvStart . This functions expect the target address and address type as parameter, which are passed to the controller when the programmer sets the advertising parameters and not known when advertising_enable is called. Therefore, this information should be kept in memory when advertising parameters are set and retrieved when advertising is enable to choose the right call to start (or stop) advertising. Timeout of direct advertising is also handled in an uncommon way, a connection timeout is received. Similarly, DmConnClose should be called to stop connectable direct advertising. The state is kept in an array of direct_adv_cb_t. Each items contains a peer address, the peer address type, the connection handle and the advertising handle as well as a state which indicate if the advertising is running, pending or not used. When advertising parameters are set, the state is updated to match the target address or disable direct advertising management for the advertising set being configured. When advertising is enabled, the pal dispatch the operation to the right calls (DmAdvStart/DmConnAccept or DmAdvStop/DmConnClose). When an advertising timeout happen or a connection is made, the pal cleans any direct advertising state of this advertising set
1 parent ced3b1c commit dd615f7

File tree

2 files changed

+323
-19
lines changed

2 files changed

+323
-19
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,59 @@ class Gap : public ::ble::pal::Gap<Gap<EH>, EH> {
414414
}
415415
};
416416

417+
/* Cordio requires the call to DmConnAccept to properly catch direct advertising timeout.
418+
* This call returns a connection ID and expect the peer address and the peer address type.
419+
* This PAL following HCI expectations, these information are not present when the higher
420+
* level calls the function to enable advertising.
421+
* This data structure caches these informations and use them in case of direct advertising.
422+
* Similarly, direct advertising timeout doesn't trigger an advertising timeout instead it
423+
* triggers a disconnection with the status 60. Information on running direct advertising
424+
* is stored here.
425+
*/
426+
struct direct_adv_cb_t {
427+
direct_adv_cb_t() :
428+
peer_address_type(advertising_peer_address_type_t::PUBLIC),
429+
state(free)
430+
{}
431+
432+
address_t peer_address;
433+
advertising_peer_address_type_t peer_address_type;
434+
advertising_handle_t advertising_handle;
435+
connection_handle_t connection_handle;
436+
bool low_duty_cycle;
437+
enum {
438+
free = 0,
439+
pending,
440+
running
441+
} state;
442+
};
443+
444+
/* Predicate expect a const reference to a direct_adv_cb_t
445+
* It must returns true if the criteria are met and false otherwise. */
446+
template<typename Predicate>
447+
direct_adv_cb_t* get_adv_cb(const Predicate& predicate);
448+
449+
direct_adv_cb_t* get_running_direct_adv_cb(advertising_handle_t adv_handle);
450+
451+
direct_adv_cb_t* get_running_conn_direct_adv_cb(connection_handle_t adv_handle);
452+
453+
direct_adv_cb_t* get_pending_direct_adv_cb(advertising_handle_t adv_handle);
454+
455+
direct_adv_cb_t* get_free_direct_adv_cb();
456+
457+
ble_error_t update_direct_advertising_parameters(
458+
advertising_handle_t advertising_handle,
459+
uint8_t advertising_type,
460+
address_t peer_address,
461+
advertising_peer_address_type_t peer_address_type
462+
);
463+
417464
private:
418465
address_t device_random_address;
419466
bool use_active_scanning;
420467
uint8_t extended_scan_type[3];
421468
phy_set_t scanning_phys;
469+
direct_adv_cb_t direct_adv_cb[DM_NUM_ADV_SETS];
422470
};
423471

424472
} // cordio

0 commit comments

Comments
 (0)