Skip to content

Commit ac359a2

Browse files
authored
Merge pull request #980 from pennam/MAC-deprecate
WiFi Ethernet fix MAC address reversed order
2 parents ec0a86b + 5c2458b commit ac359a2

File tree

3 files changed

+142
-120
lines changed

3 files changed

+142
-120
lines changed

libraries/SocketWrapper/src/SocketHelpers.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) {
55
for (int b = 0; b < 6; b++) {
66
uint32_t tmp;
77
sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp);
8-
mac[5 - b] = (uint8_t)tmp;
8+
mac[b] = (uint8_t)tmp;
99
}
10-
//sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[5], &mac[4], &mac[3], &mac[2], &mac[1], &mac[0]);
1110
return mac;
1211
}
1312

1413
String arduino::MbedSocketClass::macAddress() {
15-
return String(getNetwork()->get_mac_address());
14+
const char* mac_str = getNetwork()->get_mac_address();
15+
if (!mac_str) {
16+
return String("ff:ff:ff:ff:ff:ff");
17+
}
18+
return String(mac_str);
1619
}
1720

1821
int arduino::MbedSocketClass::setHostname(const char* hostname) {

libraries/SocketWrapper/src/SocketHelpers.h

+76-57
Original file line numberDiff line numberDiff line change
@@ -28,110 +28,129 @@ class MbedSocketClass {
2828
void config(IPAddress local_ip);
2929

3030
/* Change Ip configuration settings disabling the dhcp client
31-
*
32-
* param local_ip: Static ip configuration as string
33-
*/
31+
*
32+
* param local_ip: Static ip configuration as string
33+
*/
3434
void config(const char* local_ip);
3535

3636
/* Change Ip configuration settings disabling the dhcp client
37-
*
38-
* param local_ip: Static ip configuration
39-
* param dns_server: IP configuration for DNS server 1
40-
*/
37+
*
38+
* param local_ip: Static ip configuration
39+
* param dns_server: IP configuration for DNS server 1
40+
*/
4141
void config(IPAddress local_ip, IPAddress dns_server);
4242

4343
/* Change Ip configuration settings disabling the dhcp client
44-
*
45-
* param local_ip: Static ip configuration
46-
* param dns_server: IP configuration for DNS server 1
47-
* param gateway : Static gateway configuration
48-
*/
44+
*
45+
* param local_ip: Static ip configuration
46+
* param dns_server: IP configuration for DNS server 1
47+
* param gateway : Static gateway configuration
48+
*/
4949
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
5050

5151
/* Change Ip configuration settings disabling the dhcp client
52-
*
53-
* param local_ip: Static ip configuration
54-
* param dns_server: IP configuration for DNS server 1
55-
* param gateway: Static gateway configuration
56-
* param subnet: Static Subnet mask
57-
*/
52+
*
53+
* param local_ip: Static ip configuration
54+
* param dns_server: IP configuration for DNS server 1
55+
* param gateway: Static gateway configuration
56+
* param subnet: Static Subnet mask
57+
*/
5858
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
5959

6060
// When using DHCP the hostname provided will be used.
6161
int setHostname(const char* hostname);
6262

6363
/* Change DNS Ip configuration
64-
*
65-
* param dns_server1: ip configuration for DNS server 1
66-
*/
64+
*
65+
* param dns_server1: ip configuration for DNS server 1
66+
*/
6767
void setDNS(IPAddress dns_server1);
6868

6969
/* Change DNS Ip configuration
70-
*
71-
* param dns_server1: ip configuration for DNS server 1
72-
* param dns_server2: ip configuration for DNS server 2
73-
*
74-
*/
70+
*
71+
* param dns_server1: ip configuration for DNS server 1
72+
* param dns_server2: ip configuration for DNS server 2
73+
*
74+
*/
7575
void setDNS(IPAddress dns_server1, IPAddress dns_server2);
7676

7777
/*
78-
* Get the interface IP address.
79-
*
80-
* return: Ip address value
81-
*/
78+
* Get the interface IP address.
79+
*
80+
* return: Ip address value
81+
*/
8282
IPAddress localIP();
8383

8484
/*
85-
* Get the interface subnet mask address.
86-
*
87-
* return: subnet mask address value
88-
*/
85+
* Get the interface subnet mask address.
86+
*
87+
* return: subnet mask address value
88+
*/
8989
IPAddress subnetMask();
9090

9191
/*
92-
* Get the gateway ip address.
93-
*
94-
* return: gateway ip address value
95-
*/
92+
* Get the gateway ip address.
93+
*
94+
* return: gateway ip address value
95+
*/
9696
IPAddress gatewayIP();
9797

9898
/*
99-
* Get the DNS Server ip address.
100-
*
101-
* return: DNS Server ip address value
102-
*/
99+
* Get the DNS Server ip address.
100+
*
101+
* return: DNS Server ip address value
102+
*/
103103
IPAddress dnsServerIP();
104104

105105
/*
106-
* Get the DNS Server ip address.
107-
*
108-
* return: DNS Server ip address value
109-
*/
106+
* Get the DNS Server ip address.
107+
*
108+
* return: DNS Server ip address value
109+
*/
110110
IPAddress dnsIP(int n = 0);
111111

112112
virtual NetworkInterface* getNetwork() = 0;
113-
113+
114114
/*
115-
* Download a file from an HTTP endpoint and save it in the provided `target` location on the fs
116-
* The parameter cbk can be used to perform actions on the buffer before saving on the fs
117-
*
118-
* return: on success the size of the downloaded file, on error -status code
119-
*/
115+
* Download a file from an HTTP endpoint and save it in the provided `target` location on the fs
116+
* The parameter cbk can be used to perform actions on the buffer before saving on the fs
117+
*
118+
* return: on success the size of the downloaded file, on error -status code
119+
*/
120120
int download(
121121
const char* url, const char* target, bool const is_https = false);
122122
/*
123-
* Download a file from an HTTP endpoint and handle the body of the request on a callback
124-
* passed as an argument
125-
*
126-
* return: on success the size of the downloaded file, on error -status code
127-
*/
123+
* Download a file from an HTTP endpoint and handle the body of the request on a callback
124+
* passed as an argument
125+
*
126+
* return: on success the size of the downloaded file, on error -status code
127+
*/
128128
int download(
129129
const char* url, bool const is_https = false,
130130
mbed::Callback<void(const char*, uint32_t)> cbk = nullptr);
131131

132132
int hostByName(const char* aHostname, IPAddress& aResult);
133133

134+
/*
135+
* Get the interface MAC address.
136+
*
137+
* Network interface should be ready to get a valid mac address.
138+
* Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address
139+
* request, otherwhise returned value will be ff:ff:ff:ff:ff:ff
140+
*
141+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
142+
*/
134143
uint8_t* macAddress(uint8_t* mac);
144+
145+
/*
146+
* Get the interface MAC address String.
147+
*
148+
* Network interface should be ready to get a valid MAC address.
149+
* Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address
150+
* request, otherwhise returned value will be ff:ff:ff:ff:ff:ff
151+
*
152+
* return: MAC Address String
153+
*/
135154
String macAddress();
136155

137156
void setFeedWatchdogFunc(voidFuncPtr func);

libraries/WiFi/src/WiFi.h

+60-60
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@ class WiFiClass : public MbedSocketClass {
5555
: wifi_if(_if){};
5656

5757
/*
58-
* Get firmware version
59-
*/
58+
* Get firmware version
59+
*/
6060
static const char* firmwareVersion();
6161

6262
/* Start Wifi connection for OPEN networks
63-
*
64-
* param ssid: Pointer to the SSID string.
65-
*/
63+
*
64+
* param ssid: Pointer to the SSID string.
65+
*/
6666
int begin(const char* ssid);
6767

68-
void MACAddress(uint8_t *mac_address);
68+
void MACAddress(uint8_t *mac_address) __attribute__((deprecated("Use macAddress(uint8_t *mac_address)")));
6969

7070
/* Start Wifi connection with passphrase
71-
* the most secure supported mode will be automatically selected
72-
*
73-
* param ssid: Pointer to the SSID string.
74-
* param passphrase: Passphrase. Valid characters in a passphrase
75-
* must be between ASCII 32-126 (decimal).
76-
*/
71+
* the most secure supported mode will be automatically selected
72+
*
73+
* param ssid: Pointer to the SSID string.
74+
* param passphrase: Passphrase. Valid characters in a passphrase
75+
* must be between ASCII 32-126 (decimal).
76+
*/
7777
int begin(const char* ssid, const char* passphrase, wl_enc_type security = ENC_TYPE_UNKNOWN);
7878

7979
// Inherit config methods from the parent class
@@ -84,86 +84,86 @@ class WiFiClass : public MbedSocketClass {
8484
int beginAP(const char* ssid, const char* passphrase, uint8_t channel = DEFAULT_AP_CHANNEL);
8585

8686
/*
87-
* Disconnect from the network
88-
*
89-
* return: one value of wl_status_t enum
90-
*/
87+
* Disconnect from the network
88+
*
89+
* return: one value of wl_status_t enum
90+
*/
9191
int disconnect(void);
9292

9393
void end(void);
9494

9595
/*
96-
* Return the current SSID associated with the network
97-
*
98-
* return: ssid string
99-
*/
96+
* Return the current SSID associated with the network
97+
*
98+
* return: ssid string
99+
*/
100100
char* SSID();
101101

102102
/*
103-
* Return the current BSSID associated with the network.
104-
* It is the MAC address of the Access Point
105-
*
106-
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
107-
*/
103+
* Return the current BSSID associated with the network.
104+
* It is the MAC address of the Access Point
105+
*
106+
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
107+
*/
108108
uint8_t* BSSID(uint8_t* bssid);
109109

110110
/*
111-
* Return the current RSSI /Received Signal Strength in dBm)
112-
* associated with the network
113-
*
114-
* return: signed value
115-
*/
111+
* Return the current RSSI /Received Signal Strength in dBm)
112+
* associated with the network
113+
*
114+
* return: signed value
115+
*/
116116
int32_t RSSI();
117117

118118
/*
119-
* Return the Encryption Type associated with the network
120-
*
121-
* return: one value of wl_enc_type enum
122-
*/
119+
* Return the Encryption Type associated with the network
120+
*
121+
* return: one value of wl_enc_type enum
122+
*/
123123
uint8_t encryptionType();
124124

125125
/*
126-
* Start scan WiFi networks available
127-
*
128-
* return: Number of discovered networks
129-
*/
126+
* Start scan WiFi networks available
127+
*
128+
* return: Number of discovered networks
129+
*/
130130
int8_t scanNetworks();
131131

132132
/*
133-
* Return the SSID discovered during the network scan.
134-
*
135-
* param networkItem: specify from which network item want to get the information
136-
*
137-
* return: ssid string of the specified item on the networks scanned list
138-
*/
133+
* Return the SSID discovered during the network scan.
134+
*
135+
* param networkItem: specify from which network item want to get the information
136+
*
137+
* return: ssid string of the specified item on the networks scanned list
138+
*/
139139
char* SSID(uint8_t networkItem);
140140

141141
/*
142-
* Return the encryption type of the networks discovered during the scanNetworks
143-
*
144-
* param networkItem: specify from which network item want to get the information
145-
*
146-
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
147-
*/
142+
* Return the encryption type of the networks discovered during the scanNetworks
143+
*
144+
* param networkItem: specify from which network item want to get the information
145+
*
146+
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
147+
*/
148148
uint8_t encryptionType(uint8_t networkItem);
149149

150150
uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid);
151151
uint8_t channel(uint8_t networkItem);
152152

153153
/*
154-
* Return the RSSI of the networks discovered during the scanNetworks
155-
*
156-
* param networkItem: specify from which network item want to get the information
157-
*
158-
* return: signed value of RSSI of the specified item on the networks scanned list
159-
*/
154+
* Return the RSSI of the networks discovered during the scanNetworks
155+
*
156+
* param networkItem: specify from which network item want to get the information
157+
*
158+
* return: signed value of RSSI of the specified item on the networks scanned list
159+
*/
160160
int32_t RSSI(uint8_t networkItem);
161161

162162
/*
163-
* Return Connection status.
164-
*
165-
* return: one of the value defined in wl_status_t
166-
*/
163+
* Return Connection status.
164+
*
165+
* return: one of the value defined in wl_status_t
166+
*/
167167
uint8_t status();
168168

169169
unsigned long getTime();

0 commit comments

Comments
 (0)