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

WiFi Ethernet fix MAC address reversed order #980

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions libraries/SocketWrapper/src/SocketHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ uint8_t* arduino::MbedSocketClass::macAddress(uint8_t* mac) {
for (int b = 0; b < 6; b++) {
uint32_t tmp;
sscanf(&mac_str[b * 2 + (b)], "%02x", (unsigned int*)&tmp);
mac[5 - b] = (uint8_t)tmp;
mac[b] = (uint8_t)tmp;
}
//sscanf(mac_str, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", &mac[5], &mac[4], &mac[3], &mac[2], &mac[1], &mac[0]);
return mac;
}

String arduino::MbedSocketClass::macAddress() {
return String(getNetwork()->get_mac_address());
const char* mac_str = getNetwork()->get_mac_address();
if (!mac_str) {
return String("ff:ff:ff:ff:ff:ff");
}
return String(mac_str);
}

int arduino::MbedSocketClass::hostByName(const char* aHostname, IPAddress& aResult) {
Expand Down
133 changes: 76 additions & 57 deletions libraries/SocketWrapper/src/SocketHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,107 +28,126 @@ class MbedSocketClass {
void config(IPAddress local_ip);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration as string
*/
*
* param local_ip: Static ip configuration as string
*/
void config(const char* local_ip);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
*/
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
*/
void config(IPAddress local_ip, IPAddress dns_server);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param gateway : Static gateway configuration
*/
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param gateway : Static gateway configuration
*/
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);

/* Change Ip configuration settings disabling the dhcp client
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param gateway: Static gateway configuration
* param subnet: Static Subnet mask
*/
*
* param local_ip: Static ip configuration
* param dns_server: IP configuration for DNS server 1
* param gateway: Static gateway configuration
* param subnet: Static Subnet mask
*/
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);

/* Change DNS Ip configuration
*
* param dns_server1: ip configuration for DNS server 1
*/
*
* param dns_server1: ip configuration for DNS server 1
*/
void setDNS(IPAddress dns_server1);

/* Change DNS Ip configuration
*
* param dns_server1: ip configuration for DNS server 1
* param dns_server2: ip configuration for DNS server 2
*
*/
*
* param dns_server1: ip configuration for DNS server 1
* param dns_server2: ip configuration for DNS server 2
*
*/
void setDNS(IPAddress dns_server1, IPAddress dns_server2);

/*
* Get the interface IP address.
*
* return: Ip address value
*/
* Get the interface IP address.
*
* return: Ip address value
*/
IPAddress localIP();

/*
* Get the interface subnet mask address.
*
* return: subnet mask address value
*/
* Get the interface subnet mask address.
*
* return: subnet mask address value
*/
IPAddress subnetMask();

/*
* Get the gateway ip address.
*
* return: gateway ip address value
*/
* Get the gateway ip address.
*
* return: gateway ip address value
*/
IPAddress gatewayIP();

/*
* Get the DNS Server ip address.
*
* return: DNS Server ip address value
*/
* Get the DNS Server ip address.
*
* return: DNS Server ip address value
*/
IPAddress dnsServerIP();

/*
* Get the DNS Server ip address.
*
* return: DNS Server ip address value
*/
* Get the DNS Server ip address.
*
* return: DNS Server ip address value
*/
IPAddress dnsIP(int n = 0);

virtual NetworkInterface* getNetwork() = 0;

/*
* Download a file from an HTTP endpoint and save it in the provided `target` location on the fs
* The parameter cbk can be used to perform actions on the buffer before saving on the fs
*
* return: on success the size of the downloaded file, on error -status code
*/
* Download a file from an HTTP endpoint and save it in the provided `target` location on the fs
* The parameter cbk can be used to perform actions on the buffer before saving on the fs
*
* return: on success the size of the downloaded file, on error -status code
*/
int download(
const char* url, const char* target, bool const is_https = false);
/*
* Download a file from an HTTP endpoint and handle the body of the request on a callback
* passed as an argument
*
* return: on success the size of the downloaded file, on error -status code
*/
* Download a file from an HTTP endpoint and handle the body of the request on a callback
* passed as an argument
*
* return: on success the size of the downloaded file, on error -status code
*/
int download(
const char* url, bool const is_https = false,
mbed::Callback<void(const char*, uint32_t)> cbk = nullptr);

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

/*
* Get the interface MAC address.
*
* Network interface should be ready to get a valid mac address.
* Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address
* request, otherwhise returned value will be ff:ff:ff:ff:ff:ff
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
uint8_t* macAddress(uint8_t* mac);

/*
* Get the interface MAC address String.
*
* Network interface should be ready to get a valid MAC address.
* Call WiFi.begin("",""); or Ethernet.begin(); before issuing a mac address
* request, otherwhise returned value will be ff:ff:ff:ff:ff:ff
*
* return: MAC Address String
*/
String macAddress();

void setFeedWatchdogFunc(voidFuncPtr func);
Expand Down
120 changes: 60 additions & 60 deletions libraries/WiFi/src/WiFi.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,25 @@ class WiFiClass : public MbedSocketClass {
: wifi_if(_if){};

/*
* Get firmware version
*/
* Get firmware version
*/
static const char* firmwareVersion();

/* Start Wifi connection for OPEN networks
*
* param ssid: Pointer to the SSID string.
*/
*
* param ssid: Pointer to the SSID string.
*/
int begin(const char* ssid);

void MACAddress(uint8_t *mac_address);
void MACAddress(uint8_t *mac_address) __attribute__((deprecated("Use macAddress(uint8_t *mac_address)")));

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

// When using DHCP the hostname provided will be used.
Expand All @@ -87,86 +87,86 @@ class WiFiClass : public MbedSocketClass {
int beginAP(const char* ssid, const char* passphrase, uint8_t channel = DEFAULT_AP_CHANNEL);

/*
* Disconnect from the network
*
* return: one value of wl_status_t enum
*/
* Disconnect from the network
*
* return: one value of wl_status_t enum
*/
int disconnect(void);

void end(void);

/*
* Return the current SSID associated with the network
*
* return: ssid string
*/
* Return the current SSID associated with the network
*
* return: ssid string
*/
char* SSID();

/*
* Return the current BSSID associated with the network.
* It is the MAC address of the Access Point
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
* Return the current BSSID associated with the network.
* It is the MAC address of the Access Point
*
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
*/
uint8_t* BSSID(uint8_t* bssid);

/*
* Return the current RSSI /Received Signal Strength in dBm)
* associated with the network
*
* return: signed value
*/
* Return the current RSSI /Received Signal Strength in dBm)
* associated with the network
*
* return: signed value
*/
int32_t RSSI();

/*
* Return the Encryption Type associated with the network
*
* return: one value of wl_enc_type enum
*/
* Return the Encryption Type associated with the network
*
* return: one value of wl_enc_type enum
*/
uint8_t encryptionType();

/*
* Start scan WiFi networks available
*
* return: Number of discovered networks
*/
* Start scan WiFi networks available
*
* return: Number of discovered networks
*/
int8_t scanNetworks();

/*
* Return the SSID discovered during the network scan.
*
* param networkItem: specify from which network item want to get the information
*
* return: ssid string of the specified item on the networks scanned list
*/
* Return the SSID discovered during the network scan.
*
* param networkItem: specify from which network item want to get the information
*
* return: ssid string of the specified item on the networks scanned list
*/
char* SSID(uint8_t networkItem);

/*
* Return the encryption type of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
*/
* Return the encryption type of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
*/
uint8_t encryptionType(uint8_t networkItem);

uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid);
uint8_t channel(uint8_t networkItem);

/*
* Return the RSSI of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: signed value of RSSI of the specified item on the networks scanned list
*/
* Return the RSSI of the networks discovered during the scanNetworks
*
* param networkItem: specify from which network item want to get the information
*
* return: signed value of RSSI of the specified item on the networks scanned list
*/
int32_t RSSI(uint8_t networkItem);

/*
* Return Connection status.
*
* return: one of the value defined in wl_status_t
*/
* Return Connection status.
*
* return: one of the value defined in wl_status_t
*/
uint8_t status();

unsigned long getTime();
Expand Down