espressif / esp-hosted

Hosted Solution (Linux/MCU) with ESP32 (Wi-Fi + BT + BLE)
Other
675 stars 158 forks source link

How to change wifi, Bluetooth MAC address #317

Open xmlhp opened 8 months ago

xmlhp commented 8 months ago

We need to use the MAC address we bought. How to change the address? How to permanently save the address to esp32c3?

mantriyogesh commented 8 months ago

Please check https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/misc_system_api.html

xmlhp commented 8 months ago

This was changed in the firmware. How do I change through the driver on linux?

xmlhp commented 8 months ago

ifconfig -a

espsta0 Link encap:Ethernet HWaddr C0:4E:30:84:AA:FC
BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ifconfig espsta0 hw ether c0:4E:30:84:AA:FE

ifconfig -a

espsta0 Link encap:Ethernet HWaddr C0:4E:30:84:AA:FC
BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ifconfig espsta0 hw ether c0:4E:30:84:AA:FE

ifconfig espsta0 up

ifconfig -a

espsta0 Link encap:Ethernet HWaddr C0:4E:30:84:AA:FC
BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

I can't config the hwadder by ifconfig espsta0 hw ether xx:xx:xx:xx:xx

mantriyogesh commented 8 months ago

For Wi-Fi, the call is available, wifi_set_mac().

test_set_mac_addr() can also be used, as it calls 'wifi_set_mac()' internally.

But this clearly needs to be agnostic and need to support Bluetooth. For bluetooth, yet not available, but little change you can re-use this API for bluetooth also.

mantriyogesh commented 8 months ago

Make sure that the espsta0 mac address if for the 'STA' interface MAC address at ESP. Otherwise you will face issues in delivering packets correctly.

xmlhp commented 8 months ago

Make sure that the espsta0 mac address if for the 'STA' interface MAC address at ESP. I don't understand. What does that mean.

xmlhp commented 8 months ago

`# ifconfig -a espsta0 Link encap:Ethernet HWaddr C0:4E:30:84:AA:FC
BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

ifconfig espsta0 hw ether c0:4E:30:84:AA:CC

[89426.656494] esp32c3:esp_set_mac_address: 304 c0:4e:30:84:aa:cc [89431.716161] esp32c3:wait_and_decode_cmd_resp: Command[2] timed out ifconfig: SIOCSIFHWADDR: Invalid argument [89431.716213] esp32c3:cmd_set_mac: esp32: wait_and_decode_cmd_resp(priv, cmd_node) failure, ret: -22

ifconfig espsta0 hw ether c0:4E:30:84:AA:CC

[89456.913728] esp32c3:esp_set_mac_address: 304 c0:4e:30:84:aa:cc [89462.009439] esp32c3:wait_and_decode_cmd_resp: Command[2] timed out ifconfig: SIOCSIFHWADDR: Invalid argument [89462.009494] esp32c3:cmd_set_mac: esp32: wait_and_decode_cmd_resp(priv, cmd_node) failure, ret: -22

ifconfig espsta0 hw ether c0:4E:30:84:AA:0C

[89473.896194] esp32c3:esp_set_mac_address: 304 c0:4e:30:84:aa:0c [89479.076144] esp32c3:wait_and_decode_cmd_resp: Command[2] timed out ifconfig: SIOCSIFHWADDR: Invalid argument [89479.076197] esp32c3:cmd_set_mac: esp32: wait_and_decode_cmd_resp(priv, cmd_node) failure, ret: -22

ifconfig -a

espsta0 Link encap:Ethernet HWaddr C0:4E:30:84:AA:FC
BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

`

mantriyogesh commented 8 months ago

For Wi-Fi, the call is available, wifi_set_mac().

test_set_mac_addr() can also be used, as it calls 'wifi_set_mac()' internally.

But this clearly needs to be agnostic and need to support Bluetooth. For bluetooth, yet not available, but little change you can re-use this API for bluetooth also.

I am sorry, this is not applicable for NG. Let me check for NG.

mantriyogesh commented 8 months ago

Right, https://github.com/espressif/esp-hosted/blob/26f4fa56bb2dd8504cc24efefa03a4e5ffcd0535/esp_hosted_ng/host/main.c#L349

https://github.com/espressif/esp-hosted/blob/26f4fa56bb2dd8504cc24efefa03a4e5ffcd0535/esp_hosted_fg/host/linux/host_driver/esp32/main.c#L97

esp_set_mac_address should be automatically used, when you set mac address on interface espsta0. So the thing, you had tried, should have worked.

  1. Can you please share ESP log
  2. Which git commit do you use and what is the host git commit?

    There is also restriction of MAC address . It is JFYI, you are not using such mac address anyway:

Screenshot 2024-01-18 at 4 14 48 PM

xmlhp commented 8 months ago

ifconfig espsta0 hw ether xx:xx:xx:xx:xx @esp32c3 side fimware 1.03 is good.

I (100657) FW_MAIN: Set MAC command

E (100657) FW_CMD: Setting mac address

I (100657) FW_CMD: 0x3fcb41e4 c0 4e 30 84 98 b6 |.N0...| I (100657) wifi:enable tsf I (100657) FW_CMD: Unregistered event: 3

I (100667) FW_CMD: Wifi Sta mode set

I (159657) FW_MAIN: Scan request

I (161377) FW_MAIN: Auth request

I (161577) FW_CMD: AP not found to connect. I (161697) FW_MAIN: Scan request

I (163407) FW_MAIN: Auth request

I (163607) FW_CMD: AP not found to connect. I (164127) FW_MAIN: Scan request

I (165847) FW_MAIN: Auth request

I (166047) FW_CMD: Connecting to SW_TEST_TEAM, channel: 11 [4] I (166047) FW_CMD: AUTH Commit

E (166057) wifi:null wpa_sta_ap_set_rsnxe I (166057) wifi:new:<11,2>, old:<1,0>, ap:<255,255>, sta:<11,2>, prof:1 I (166057) wifi:state: init -> auth (b0) I (166067) FW_CMD: handle_wpa_sta_rx_mgmt:635 Auth[11] recvd

I (166087) FW_MAIN: Assoc request

I (166087) wifi:state: auth -> assoc (0) I (166087) wifi:state: assoc -> run (10) I (166087) FW_CMD: handle_wpa_sta_rx_mgmt:643 ASSOC Resp[1] recvd

I (166087) FW_CMD: STA connect event [channel 11]

I (166097) BSSID: 0x3fcb426a f4 84 8d fb 5a 17 |....Z.| I (166157) FW_MAIN: Add key request

I (166157) FW_CMD: process_add_key:1784

I (166177) FW_MAIN: Set default key request

I (166197) FW_MAIN: Add key request

I (166197) FW_CMD: process_add_key:1784

xmlhp commented 8 months ago

Then, how set the mac for bluetooth?

mantriyogesh commented 8 months ago

For Bluetooth yet not supported, need to add this support.