Commit 7f05c41a authored by Philippe De Swert's avatar Philippe De Swert

Add random mac generator for g_ether so networking tools and scripts on host...

Add random mac generator for g_ether so networking tools and scripts on host side are easier to use/automate
Signed-off-by: default avatarPhilippe De Swert <philippe.deswert@jollamobile.com>
parent e4e0be40
usb-moded (0.57) unstable; urgency=low
* Add random mac generator so host based network tools always get the same mac
-- Philippe De Swert <philippedeswert@jollamobile.com> Thu, 17 Jan 2013 19:50:37 +0200
usb-moded (0.56) unstable; urgency=low
* Fix possible compiltation issue with N900 support and android which are mutually exclusive
......
......@@ -26,7 +26,9 @@ usb_moded_SOURCES = \
usb_moded-network.c \
usb_moded-network.h \
usb_moded-modesetting.c \
usb_moded-modesetting.h
usb_moded-modesetting.h \
usb_moded-mac.c \
usb_moded-mac.h
if !ANDROID
usb_moded_SOURCES += \
......
/**
@file usb_moded-mac.c
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include <stdio.h>
#include "usb_moded-mac.h"
static void random_ether_addr(unsigned char *addr)
{
FILE *random;
random = fopen("/dev/urandom", "r");
fread(addr, 1, 6, random);
fclose(random);
addr [0] &= 0xfe; /* clear multicast bit */
addr [0] |= 0x02; /* set local assignment bit (IEEE802) */
}
void generate_random_mac (void)
{
unsigned char addr[6];
int i;
FILE *g_ether;
printf("Getting random usb ethernet mac\n");
random_ether_addr(addr);
g_ether = fopen("/etc/modprobe.d/g_ether.conf", "w");
fprintf(g_ether, "options g_ether host_addr=");
for(i=0; i<5; i++)
{
fprintf(g_ether, "%02x:",addr[i]);
}
fprintf(g_ether, "%02x",addr[i]);
fclose(g_ether);
}
/**
@file usb_moded-mac.h
Copyright (C) 2013 Jolla. All rights reserved.
@author: Philippe De Swert <philippe.deswert@jollamobile.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the Lesser GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the Lesser GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
void generate_random_mac (void);
......@@ -49,6 +49,7 @@
#include "usb_moded-config.h"
#include "usb_moded-config-private.h"
#include "usb_moded-network.h"
#include "usb_moded-mac.h"
/* global definitions */
......@@ -180,7 +181,7 @@ void set_usb_connected_state(void)
#ifdef MEEGOLOCK
int act_dead = 0;
/* check if we are in acting dead or not, /tmp/USER will not exist in acting dead */
act_dead = access("/tmp/USER", R_OK);
act_dead = accesa("/tmp/USER", R_OK);
if(mode_to_set && !export && !act_dead)
#else
if(mode_to_set)
......@@ -455,6 +456,10 @@ static void usb_moded_init(void)
ctx = kmod_new(NULL, NULL);
kmod_load_resources(ctx);
if(!access("/etc/modprobe.d/g_ether.conf", F_OK))
{
generate_random_mac();
}
/* TODO: add more start-up clean-up and init here if needed */
}
......
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