Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
33
WICED_BT_TRACE(
"Power mgmt status event: bd (%B) status:%d hci_status:%d\n"
,
p_power_mgmt_notification->
bd_addr
, \
p_power_mgmt_notification->
status
, p_power_mgmt_notification->
hci_status
);
break
;
case
BTM_BLE_ADVERT_STATE_CHANGED_EVT
:
p_mode = &p_event_data->
ble_advert_state_changed
;
WICED_BT_TRACE(
"Advertisement State Change: %d\n"
, *p_mode);
if
( *p_mode ==
BTM_BLE_ADVERT_OFF
)
{
hello_sensor_advertisement_stopped();
}
break
;
case
BTM_SECURITY_REQUEST_EVT
:
wiced_bt_ble_security_grant( p_event_data->
security_request
.
bd_addr
,
WICED_BT_SUCCESS
);
break
;
case
BTM_PAIRING_IO_CAPABILITIES_BLE_REQUEST_EVT
:
p_event_data->
pairing_io_capabilities_ble_request
.
local_io_cap
=
BTM_IO_CAPABILITIES_NONE
;
p_event_data->
pairing_io_capabilities_ble_request
.
oob_data
=
BTM_OOB_NONE
;
p_event_data->
pairing_io_capabilities_ble_request
.
auth_req
=
BTM_LE_AUTH_REQ_SC_BOND
;
p_event_data->
pairing_io_capabilities_ble_request
.
max_key_size
= 0x10;
p_event_data->
pairing_io_capabilities_ble_request
.
init_keys
=
BTM_LE_KEY_PENC
|
BTM_LE_KEY_PID
|
BTM_LE_KEY_PCSRK
|
BTM_LE_KEY_LENC
;
p_event_data->
pairing_io_capabilities_ble_request
.
resp_keys
=
BTM_LE_KEY_PENC
|
BTM_LE_KEY_PID
|
BTM_LE_KEY_PCSRK
|
BTM_LE_KEY_LENC
;
break
;
default
:
result =
WICED_BT_USE_DEFAULT_SECURITY
;
break
;
}
return
result;
}
7 . 4 . 3
B L E F u n c t i o n s
Advertisement data can be modified based on application requirements by adding/removing necessary elements in the
wiced_bt_ble_advert_elem_t
. In this example, BLE device advertisement name is
set to “Hello”.
Code 18.
hello_sensor_set_advertisement_data
: BLE Advertisement Data
void
hello_sensor_set_advertisement_data
(
void
)
{
wiced_bt_ble_advert_elem_t
adv_elem[4];
uint8_t
num_elem = 0;
uint8_t
flag = BTM_BLE_GENERAL_DISCOVERABLE_FLAG | BTM_BLE_BREDR_NOT_SUPPORTED;
/*
* hci_control_le_local_name - Advertising Complete Name
* Note : Max Length is 8 bytes for the Advertisement Name, rest of 21 bytes are used for
* BTM_BLE_ADVERT_TYPE_FLAG,BTM_BLE_ADVERT_TYPE_128SRV_COMPLETE
*/
uint8_t
hci_control_le_local_name[] =
"Hello"
;
//Alternate way to declare {'h', 'e', 'l', 'l',
'o', 0x00, 0x00};
uint8_t
hello_service_uuid[LEN_UUID_128] = { UUID_HELLO_SERVICE };
adv_elem[num_elem].
advert_type
=
BTM_BLE_ADVERT_TYPE_FLAG
;
adv_elem[num_elem].
len
=
sizeof
(
uint8_t
);
adv_elem[num_elem].
p_data
= &flag;
n+;
adv_elem[num_elem].
advert_type
=
BTM_BLE_ADVERT_TYPE_128SRV_COMPLETE
;
adv_elem[num_elem].
len
=
sizeof
(hello_service_uuid);
adv_elem[num_elem].
p_data
= (
uint8_t
* )hello_service_uuid;
n+;
adv_elem[num_elem].
advert_type
=
BTM_BLE_ADVERT_TYPE_NAME_COMPLETE
;
adv_elem[num_elem].
len
= strlen(hci_control_le_local_name);
adv_elem[num_elem].
p_data
= (
uint8_t
* )hci_control_le_local_name;
n+;
wiced_bt_ble_set_raw_advertisement_data(num_elem, adv_elem);
}