File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,18 @@ WEAK int mbed_uid(char *uid) {
81
81
}
82
82
#endif
83
83
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 , uint8_t coerce_mac_control_bits ) {
88
+ memcpy (manual_mac_address , mac , 6 );
89
+ manual_mac_address_set = 1 ;
90
+ if (coerce_mac_control_bits ) {
91
+ manual_mac_address [0 ] |= 0x02 ; // force bit 1 to a "1" = "Locally Administered"
92
+ manual_mac_address [0 ] &= 0xFE ; // force bit 0 to a "0" = Unicast
93
+ }
94
+ }
95
+
84
96
WEAK void mbed_mac_address (char * mac ) {
85
97
#if DEVICE_SEMIHOST
86
98
char uid [DEVICE_ID_LENGTH + 1 ];
@@ -101,12 +113,16 @@ WEAK void mbed_mac_address(char *mac) {
101
113
mac [0 ] &= ~0x01 ; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
102
114
} else { // else return a default MAC
103
115
#endif
116
+ if (manual_mac_address_set ) {
117
+ memcpy (mac , manual_mac_address , 6 );
118
+ } else {
104
119
mac [0 ] = 0x00 ;
105
120
mac [1 ] = 0x02 ;
106
121
mac [2 ] = 0xF7 ;
107
122
mac [3 ] = 0xF0 ;
108
123
mac [4 ] = 0x00 ;
109
124
mac [5 ] = 0x00 ;
125
+ }
110
126
#if DEVICE_SEMIHOST
111
127
}
112
128
#endif
Original file line number Diff line number Diff line change @@ -98,6 +98,18 @@ int mbed_interface_uid(char *uid);
98
98
99
99
#endif
100
100
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
+ * @param coerce_mac_control_bits An 8-bit int that is used as a boolean flag to either coerce
108
+ * the provided MAC address to be Locally Administered and Unicast or to use the
109
+ * provided MAC address unmodified
110
+ */
111
+ void mbed_set_mac_address (const char * mac , uint8_t coerce_mac_control_bits );
112
+
101
113
/** This returns a unique 6-byte MAC address, based on the interface UID
102
114
* If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00)
103
115
*
You can’t perform that action at this time.
0 commit comments