Пример #1
0
void nrx_px_wlock(struct nrx_px_softc *sc)
{
   RWLOCK_WLOCK(&sc->px_lock);
}
int get_mac_addr(char* mac)
{
	int status;
	char filename[128];
	char filebuf[128];
	RWLOCK_INIT(&mac_lock);
	
	RWLOCK_WLOCK(&mac_lock);
	memset(filebuf, 0, 128);
	printk("%s : enter\n", __func__);
	// 1. if "mac.bin" exist ?
	make_filename(filename, sizeof(filename), "mac.bin");
	status = mac_read_file(filebuf, filename);
	if(status < 0) {
		//printk("Not find file: %s!\n", filename);
	}
	else {
		printk("Find file: %s \n", filename);
		memcpy(&(registry.general.macAddress), filebuf, 6);
		goto _exit;
	}
	#if 0
	// 2. if mib file mac available ?
	if(macaddr_valid(mac, 6)) {
		printk("Find mac in mib file or EEPROM\n");
		memcpy(filebuf, mac, 6);
		goto _exit;
	}
	#endif

#ifdef WINNER_SN2MAC
	// 2. if mac.sn exist ?
	make_filename(filename, sizeof(filename), "mac.sn");
	status = mac_read_file(filebuf, filename);
	if(status < 0) {
		if(sn_to_mac(filebuf)==TRUE)
		{
			printk("sn_to_mac : %02X:%02X:%02X:%02X:%02X:%02X\n", filebuf[0], filebuf[1], filebuf[2], filebuf[3], filebuf[4], filebuf[5]);
			mac_write_file(filebuf, 6, filename);
			goto _exit;
		}
	}
	else {
		printk("Find file %s\n", filename);
		goto _exit;
	}
#endif

	// 3. if mac.random exist ?
	make_filename(filename, sizeof(filename), "mac.random");
	status = mac_read_file(filebuf, filename);
	if(status < 0) {
		//printk("Not find file: %s!\n", filename);
	}
	else {
		printk("Find file %s\n", filename);
		goto _exit;
	}
	// 4. mac.random not exist, generate it
	printk("No mac , generate random one!\n");
	WiFiEngine_RandomMAC(0, filebuf, 6);
	memcpy(filebuf, MAC_PREFIX, strlen(MAC_PREFIX));

	//mac_write_file(filebuf, 6, filename);

_exit:
	RWLOCK_WUNLOCK(&mac_lock);
	memcpy(mac, filebuf, 6);
	printk("mac = %02X:%02X:%02X:%02X:%02X:%02X\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
	return 0;
}