Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I change the BT MAC address via esp-hosted-fg?I was used linux driver. #501

Open
3 tasks done
244219195 opened this issue Sep 28, 2024 · 5 comments
Open
3 tasks done

Comments

@244219195
Copy link

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate.
  • Provided a clear description of your suggestion.
  • Included any relevant context or examples.

Issue or Suggestion Description

I want to add device node in linux .and then .,i can set this node value to set BT mac for ESP32 -C3 .if have other way to set the BT MAC address.Please tell me .Actually, my idea is to be able to set the Bluetooth address through Linux instead of using the default address.however ,my linux kernel is low ,it can"t support python.

@mantriyogesh
Copy link
Collaborator

Hello @244219195 , yes this needs to be added.

Plan would be to make wifi_set_mac deprecated and add up additional mode (diff name then with uint32) for Bluetooth with newer api, set_mac()

We will add this support and let you know. However, It might take some time.

For your case, you can just make small changes and re-use this API at higher layer, with hacks to handle bluetooth case, at both esp and host side code.

@244219195
Copy link
Author

Can you provide some examples?

@mantriyogesh
Copy link
Collaborator

Slave side hack

Get

if (req->req_get_mac_address->mode == WIFI_MODE_STA) {
ret = esp_wifi_get_mac(ESP_IF_WIFI_STA , mac);
ESP_LOGI(TAG,"Get station mac address");
if (ret) {
ESP_LOGE(TAG,"Error in getting MAC of ESP Station %d", ret);
goto err;
}
} else if (req->req_get_mac_address->mode == WIFI_MODE_AP) {
ret = esp_wifi_get_mac(ESP_IF_WIFI_AP, mac);
ESP_LOGI(TAG,"Get softap mac address");
if (ret) {
ESP_LOGE(TAG,"Error in getting MAC of ESP softap %d", ret);
goto err;
}

Set

if (req->req_set_mac_address->mode == WIFI_MODE_STA) {
interface = WIFI_IF_STA;
} else if (req->req_set_mac_address->mode == WIFI_MODE_AP) {
interface = WIFI_IF_AP;
} else {
ESP_LOGE(TAG, "Invalid mode to set MAC address");
goto err;
}
ret = esp_wifi_set_mac(interface, mac);
if (ret == ESP_ERR_WIFI_MODE) {
ESP_LOGE(TAG, "ESP32 mode is different than asked one");
goto err;
} else if (ret == ESP_ERR_WIFI_MAC) {
ESP_LOGE(TAG, "station and softap interface has same MAC address. OR");
ESP_LOGE(TAG, "Invalid MAC Address, The bit 0 of the first byte of ESP32 MAC address can not be 1, For example, the MAC address can set to be 1a:XX:XX:XX:XX:XX, but can not be 15:XX:XX:XX:XX:XX");
goto err;
} else if (ret) {
ESP_LOGE(TAG, "Failed to set MAC address, error %d ", ret);
goto err;
}

Host side hack

Get

Add test_get_bt_mac_addr() similar to

if (mode == WIFI_MODE_STA) {
strncpy(sta_mac_str, resp->u.wifi_mac.mac, MAC_ADDR_LENGTH);
} else if (mode == WIFI_MODE_AP) {
strncpy(softap_mac_str, resp->u.wifi_mac.mac, MAC_ADDR_LENGTH);
}

Set

return test_set_mac_addr(WIFI_MODE_STA, STATION_MODE_MAC_ADDRESS);

@mantriyogesh
Copy link
Collaborator

Above are not exactly the solution, but the code places to hack, to easily get your work done for now.

@244219195
Copy link
Author

Thanks,mantriyogesh.
Looking forward to the development of MAC address configuration in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants