Skip to content

Commit

Permalink
Read mac back from /etc/modprobe.d for use with android gadget
Browse files Browse the repository at this point in the history
[usb-moded] use android gadget mac

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed Aug 14, 2013
1 parent 476d8c7 commit 82c4e2f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/usb_moded-android.c
Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
}
}

}
25 changes: 25 additions & 0 deletions src/usb_moded-mac.c
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/usb_moded-mac.h
Expand Up @@ -21,3 +21,4 @@
*/

void generate_random_mac (void);
char * read_mac(void);

0 comments on commit 82c4e2f

Please sign in to comment.