Skip to content

Commit 6862912

Browse files
kegilbertgeky
authored andcommitted
Add ability to set MAC address to custom value
1 parent 4d672e0 commit 6862912

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

platform/mbed_interface.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ WEAK int mbed_uid(char *uid) {
8181
}
8282
#endif
8383

84+
static uint8_t manual_mac_address_set = 0;
85+
static char manual_mac_address[6];
86+
87+
void mbed_set_mac_address(const char *mac) {
88+
memcpy(manual_mac_address, mac, 6);
89+
manual_mac_address_set = 1;
90+
}
91+
8492
WEAK void mbed_mac_address(char *mac) {
8593
#if DEVICE_SEMIHOST
8694
char uid[DEVICE_ID_LENGTH + 1];
@@ -101,12 +109,16 @@ WEAK void mbed_mac_address(char *mac) {
101109
mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
102110
} else { // else return a default MAC
103111
#endif
112+
if(manual_mac_address_set) {
113+
memcpy(mac, manual_mac_address, 6);
114+
} else {
104115
mac[0] = 0x00;
105116
mac[1] = 0x02;
106117
mac[2] = 0xF7;
107118
mac[3] = 0xF0;
108119
mac[4] = 0x00;
109120
mac[5] = 0x00;
121+
}
110122
#if DEVICE_SEMIHOST
111123
}
112124
#endif

platform/mbed_interface.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ int mbed_interface_uid(char *uid);
9898

9999
#endif
100100

101+
/** This provides a generic function to set a unique 6-byte MAC address based on the passed
102+
* parameter character array. Provides no MAC address validity checking
103+
*
104+
* mbed_mac_address() will readback this configured value
105+
*
106+
* @param mac A 6-byte array containing the desired MAC address to be set
107+
*/
108+
void mbed_set_mac_address(const char *mac);
109+
101110
/** This returns a unique 6-byte MAC address, based on the interface UID
102111
* If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00)
103112
*

0 commit comments

Comments
 (0)