Skip to content

Commit

Permalink
os/board/rtl8730e: get BLE MAC address before BLE init
Browse files Browse the repository at this point in the history
- add hci_platform_get_ble_mac_address api to get address from efuse
- hci_platform_get_ble_mac_address can be used before BLE init
  • Loading branch information
yeetee179 authored and hs36-kim committed Nov 13, 2024
1 parent 830c750 commit 84f4252
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 0 additions & 2 deletions framework/src/ble_manager/ble_manager_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,6 @@ ble_result_e blemgr_handle_request(blemgr_msg_s *msg)
} break;

case BLE_CMD_GET_MAC: {
BLE_STATE_CHECK;

uint8_t *mac = (uint8_t *)msg->param;
if (mac == NULL) {
ret = TRBLE_INVALID_ARGS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,3 +1186,18 @@ uint8_t hci_platform_get_patch_cmd_buf(uint8_t *cmd_buf, uint8_t cmd_len)

return HCI_SUCCESS;
}

uint8_t hci_platform_get_ble_mac_address(uint8_t *ble_addr){
uint8_t *pbuf;

/* Read Logic Efuse */
pbuf = osif_mem_alloc(RAM_TYPE_DATA_ON, 6);
if (!pbuf || _FAIL == OTP_LogicalMap_Read(pbuf, 0x1B4, 6)) {
HCI_ERR("BT MAC address read failed");
return HCI_FAIL;
}

memcpy(ble_addr, pbuf, 6);
osif_mem_free(pbuf);
return HCI_SUCCESS;
}
19 changes: 18 additions & 1 deletion os/board/rtl8730e/src/component/os/tizenrt/rtk_blemgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ static void _reverse_mac(uint8_t *mac, uint8_t *target)
}
}

static bool _check_mac_empty(uint8_t mac[TRBLE_BD_ADDR_MAX_LEN])
{
for (int i = 0; i < TRBLE_BD_ADDR_MAX_LEN; i++) {
if (mac[i] != 0){
return false;
}
}
return true;
}

/*** Common ***/
trble_result_e trble_netmgr_init(struct bledev *dev, trble_client_init_config *client, trble_server_init_config *server);
trble_result_e trble_netmgr_deinit(struct bledev *dev);
Expand Down Expand Up @@ -234,7 +244,14 @@ trble_result_e trble_netmgr_deinit(struct bledev *dev)

trble_result_e trble_netmgr_get_mac_addr(struct bledev *dev, uint8_t mac[TRBLE_BD_ADDR_MAX_LEN])
{
memcpy(mac, dev->hwaddr, TRBLE_BD_ADDR_MAX_LEN);
if (_check_mac_empty(dev->hwaddr)){
if (!hci_platform_get_ble_mac_address(mac))
{
return TRBLE_FAIL;
}
} else {
memcpy(mac, dev->hwaddr, TRBLE_BD_ADDR_MAX_LEN);
}
return TRBLE_SUCCESS;
}

Expand Down

0 comments on commit 84f4252

Please sign in to comment.