WEAK void mbed_mac_address(char *mac) { #if DEVICE_SEMIHOST char uid[DEVICE_ID_LENGTH + 1]; int i; // if we have a UID, extract the MAC if (mbed_interface_uid(uid) == 0) { char *p = uid; #if defined(DEVICE_MAC_OFFSET) p += DEVICE_MAC_OFFSET; #endif for (i=0; i<6; i++) { int byte; sscanf(p, "%2x", &byte); mac[i] = byte; p += 2; } mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b) } else { // else return a default MAC #endif mac[0] = 0x00; mac[1] = 0x02; mac[2] = 0xF7; mac[3] = 0xF0; mac[4] = 0x00; mac[5] = 0x00; #if DEVICE_SEMIHOST } #endif }
int main() { char uid[DEVICE_ID_LENGTH + 1] = {0}; bool result = true; const int ret = mbed_interface_uid(uid); if (ret == 0) { printf("UID: %s\r\n", uid); } else { result = false; } char mac[6] = {0}; // @param mac A 6-byte array to write the MAC address mbed_mac_address(mac); printf("MAC Address: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); if (mac[0] == MAC_VENDOR_ARM_0 && mac[1] == MAC_VENDOR_ARM_1 && mac[2] == MAC_VENDOR_ARM_2) { printf("MAC Address Prefix: 00:02:F7, Vendor: ARM\r\n"); } notify_completion(result); return 0; }
WEAK int mbed_uid(char *uid) { return mbed_interface_uid(uid); }