[PATCH 2/5] Use locally adminstered mac if file is not available

Olof Johansson dev at skyshaper.net
Thu May 23 07:49:43 EDT 2013


If there is no mac address file available for all but the first
interface use locally administered mac addresses. This is ok since
they will be used for p2p action where locally administered addresses
are ok. The locally administered addresses will be based on the
address for interface one.

If the mac address file is missing for the first interface we still
randomize one to use.

Signed-off-by: Olof Johansson <dev at skyshaper.net>
---
 main.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/main.c b/main.c
index 644cd37..87a61c1 100644
--- a/main.c
+++ b/main.c
@@ -502,15 +502,28 @@ static int wcn36xx_read_mac_addresses(struct wcn36xx *wcn)
 	char *files[1] = {MAC_ADDR_0};
 	int i;

-	for (i = 0; i < ARRAY_SIZE(files); i++) {
-		status = request_firmware(&addr_file, files[i], wcn->dev);
+	for (i = 0; i < ARRAY_SIZE(wcn->addresses); i++) {
+		if (i > ARRAY_SIZE(files) - 1) {
+			status = -1;
+		} else {
+			status = request_firmware(&addr_file, files[i], wcn->dev);
+		}

 		if (status) {
 			wcn36xx_warn("Failed to read macaddress file %s, using a random
address instead",
 				     files[i]);
-			/* Assign a random mac address with Qualcomm oui */
-			memcpy(wcn->addresses[i].addr, qcom_oui, 3);
-			get_random_bytes(wcn->addresses[i].addr + 3, 3);
+			if (i == 0) {
+				/* Assign a random mac address with Qualcomm oui */
+				memcpy(wcn->addresses[i].addr, qcom_oui, 3);
+				get_random_bytes(wcn->addresses[i].addr + 3, 3);
+			} else {
+				/* Assign locally administered mac addresses to
+				 * all but the first mac */
+				memcpy(wcn->addresses[i].addr,
+				       wcn->addresses[0].addr, ETH_ALEN);
+				wcn->addresses[i].addr[0] |= BIT(1);
+				get_random_bytes(wcn->addresses[i].addr + 3, 3);
+			}

 		} else {
 			memset(tmp, 0, sizeof(tmp));
-- 
1.8.2.2



More information about the wcn36xx mailing list