Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
113
wiced_result_t
app_management_callback
(
wiced_bt_management_evt_t
event,
wiced_bt_management_evt_data_t
*p_event_data)
{
wiced_result_t
result =
WICED_BT_SUCCESS
;
wiced_bt_dev_status_t
dev_status;
wiced_bt_dev_pairing_info_t
* p_pairing_info;
wiced_bt_dev_encryption_status_t
* p_encryption_status;
int
bytes_written, bytes_read;
wiced_bt_power_mgmt_notification_t
* p_power_mgmt_notification;
WICED_BT_TRACE(
"bt_management_callback 0x%02x\n"
, event);
switch
(event)
{
/* Bluetooth stack enabled */
case
BTM_ENABLED_EVT
:
application_init();
hello_sensor_application_init();
WICED_BT_TRACE(
"Free mem:%d"
, wiced_memory_get_free_bytes());
break
;
case
BTM_DISABLED_EVT
:
break
;
case
BTM_PIN_REQUEST_EVT
:
WICED_BT_TRACE(
"remote address= %B\n"
, p_event_data->
pin_request
.
bd_addr
);
wiced_bt_dev_pin_code_reply(*p_event_data->
pin_request
.
bd_addr
,result
/*WICED_BT_SUCCESS*/
,4, &pincode[0]);
break
;
case
BTM_USER_CONFIRMATION_REQUEST_EVT
:
/* This application always confirms peer's attempt to pair */
wiced_bt_dev_confirm_req_reply (
WICED_BT_SUCCESS
, p_event_data->
user_confirmation_request
.
bd_addr
);
break
;
case
BTM_PAIRING_IO_CAPABILITIES_BR_EDR_REQUEST_EVT
:
/* This application supports only Just Works pairing */
WICED_BT_TRACE(
"BTM_PAIRING_IO_CAPABILITIES_REQUEST_EVT bda %B\n"
, p_event_data-
>
pairing_io_capabilities_br_edr_request
.
bd_addr
);
p_event_data->
pairing_io_capabilities_br_edr_request
.
local_io_cap
=
BTM_IO_CAPABILITIES_NONE
;
p_event_data->
pairing_io_capabilities_br_edr_request
.
auth_req
=
BTM_AUTH_SINGLE_PROFILE_GENERAL_BONDING_NO
;
break
;
case
BTM_PAIRING_COMPLETE_EVT
:
p_pairing_info = &p_event_data->
pairing_complete
.
pairing_complete_info
;
WICED_BT_TRACE(
"Pairing Complete: %d\n"
, p_pairing_info->
br_edr
.
status
);
result =
WICED_BT_USE_DEFAULT_SECURITY
;
break
;
case
BTM_ENCRYPTION_STATUS_EVT
:
p_encryption_status = &p_event_data->
encryption_status
;
WICED_BT_TRACE(
"Encryption Status Event: bd (%B) res %d\n"
, p_encryption_status->
bd_addr
,
p_encryption_status->
result
);
break
;
case
BTM_PAIRED_DEVICE_LINK_KEYS_UPDATE_EVT
:
/* This application supports a single paired host, we can save keys under the same NVRAM ID overwriting
previous pairing if any */
bt_write_nvram(SPP_NVRAM_ID,
sizeof
(
wiced_bt_device_link_keys_t
), &p_event_data-
>
paired_device_link_keys_update
);
break
;
case
BTM_PAIRED_DEVICE_LINK_KEYS_REQUEST_EVT
:
/* read existing key from the NVRAM */
if
(bt_read_nvram(SPP_NVRAM_ID, &p_event_data->
paired_device_link_keys_request
,
sizeof
(
wiced_bt_device_link_keys_t
)) != 0)
{
result =
WICED_BT_SUCCESS
;
}
else
{
result =
WICED_BT_ERROR
;
WICED_BT_TRACE(
"Key retrieval failure\n"
);
}
break
;
case
BTM_POWER_MANAGEMENT_STATUS_EVT
:
p_power_mgmt_notification = &p_event_data->
power_mgmt_notification
;
WICED_BT_TRACE(
"Power mgmt status event: bd (%B) status:%d hci_status:%d\n"
, p_power_mgmt_notification-
>
bd_addr
, \