Commit 82c4e2f4 authored by Philippe De Swert's avatar Philippe De Swert

Read mac back from /etc/modprobe.d for use with android gadget

[usb-moded] use android gadget mac
Signed-off-by: default avatarPhilippe De Swert <philippe.deswert@jollamobile.com>
parent 476d8c72
......@@ -27,6 +27,7 @@
#include "usb_moded-log.h"
#include "usb_moded-modesetting.h"
#include "usb_moded-config.h"
#include "usb_moded-mac.h"
/** check if android settings are set
*
......@@ -72,5 +73,12 @@ void android_init_values(void)
write_to_file("/sys/class/android_usb/android0/idProduct", text);
g_free((char *)text);
}
text = read_mac();
if(text)
{
write_to_file("/sys/class/android_usb/f_rndis/ethaddr", text);
g_free((char *)text);
}
}
}
......@@ -66,3 +66,28 @@ void generate_random_mac (void)
fprintf(g_ether, "%02x\n",addr[i]);
fclose(g_ether);
}
char * read_mac(void)
{
FILE *g_ether;
char *mac = NULL, *ret = NULL;
size_t read = 0;
g_ether = fopen("/etc/modprobe.d/g_ether.conf", "r");
if(!g_ether)
{
log_warning("Failed to read mac address from /etc/modprobe.d/g_ether.conf\n");
return(NULL);
}
fseek(g_ether, 26, SEEK_SET);
mac = malloc(sizeof(char) *17);
if(mac)
read = fread(mac, 1, 17, g_ether);
log_debug("mac = %s, read = %d\n", mac, read);
if(read == 17)
ret = strndup(mac,17);
else
ret = 0;
free(mac);
return(ret);
}
......@@ -21,3 +21,4 @@
*/
void generate_random_mac (void);
char * read_mac(void);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment