Skip to content

Commit

Permalink
Add new WiFi.APClientMacAddress API, BSSID returns local MAC in AP mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepmistry committed Sep 8, 2016
1 parent 6450ecd commit 9d620b7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/AP_SimpleWebServer/AP_SimpleWebServer.ino
Expand Up @@ -80,7 +80,7 @@ void loop() {

// a device has connected to the AP
Serial.print("Device connected to AP, MAC address: ");
WiFi.BSSID(remoteMac);
WiFi.APClientMacAddress(remoteMac);
Serial.print(remoteMac[5], HEX);
Serial.print(":");
Serial.print(remoteMac[4], HEX);
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Expand Up @@ -34,6 +34,7 @@ subnetMask KEYWORD2
gatewayIP KEYWORD2
SSID KEYWORD2
BSSID KEYWORD2
APClientMacAddress KEYWORD2
RSSI KEYWORD2
encryptionType KEYWORD2
getResult KEYWORD2
Expand Down
35 changes: 27 additions & 8 deletions src/WiFi.cpp
Expand Up @@ -150,12 +150,12 @@ static void wifi_cb(uint8_t u8MsgType, void *pvMsg)
{
tstrM2MConnInfo *pstrConnInfo = (tstrM2MConnInfo*)pvMsg;

if (WiFi._bssid) {
if (WiFi._remoteMacAddress) {
// reverse copy the remote MAC
for(int i = 0; i < 6; i++) {
WiFi._bssid[i] = pstrConnInfo->au8MACAddress[5-i];
WiFi._remoteMacAddress[i] = pstrConnInfo->au8MACAddress[5-i];
}
WiFi._bssid = 0;
WiFi._remoteMacAddress = 0;
}
}
break;
Expand Down Expand Up @@ -602,19 +602,38 @@ char* WiFiClass::SSID()

uint8_t* WiFiClass::BSSID(uint8_t* bssid)
{
_bssid = bssid;
memset(bssid, 0, 6);
if (_mode == WL_AP_MODE) {
return macAddress(bssid);
} else {
return remoteMacAddress(bssid);
}
}

uint8_t* WiFiClass::APClientMacAddress(uint8_t* mac)
{
if (_mode == WL_AP_MODE) {
return remoteMacAddress(mac);
} else {
memset(mac, 0, 6);
return mac;
}
}

uint8_t* WiFiClass::remoteMacAddress(uint8_t* remoteMacAddress)
{
_remoteMacAddress = remoteMacAddress;
memset(remoteMacAddress, 0, 6);

m2m_wifi_get_connection_info();

// Wait for connection or timeout:
unsigned long start = millis();
while (_bssid != 0 && millis() - start < 1000) {
while (_remoteMacAddress != 0 && millis() - start < 1000) {
m2m_wifi_handle_events(NULL);
}

_bssid = 0;
return bssid;
_remoteMacAddress = 0;
return remoteMacAddress;
}

int32_t WiFiClass::RSSI()
Expand Down
4 changes: 3 additions & 1 deletion src/WiFi101.h
Expand Up @@ -80,7 +80,7 @@ class WiFiClass
uint32_t _gateway;
int _dhcp;
uint32_t _resolve;
byte *_bssid;
byte *_remoteMacAddress;
wl_mode_t _mode;
wl_status_t _status;
char _scan_ssid[M2M_MAX_SSID_LEN];
Expand Down Expand Up @@ -142,6 +142,7 @@ class WiFiClass
int32_t RSSI();
uint8_t encryptionType();
uint8_t* BSSID(uint8_t* bssid);
uint8_t* APClientMacAddress(uint8_t* mac);
int8_t scanNetworks();
char* SSID(uint8_t pos);
int32_t RSSI(uint8_t pos);
Expand All @@ -168,6 +169,7 @@ class WiFiClass

uint8_t startConnect(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo);
uint8_t startAP(const char *ssid, uint8_t u8SecType, const void *pvAuthInfo, uint8_t channel);
uint8_t* remoteMacAddress(uint8_t* remoteMacAddress);
};

extern WiFiClass WiFi;
Expand Down

0 comments on commit 9d620b7

Please sign in to comment.