--- /dev/null
+/*\r
+ * Copyright (C) 2010 ROCKCHIP, Inc.\r
+ * Author: roger_chen <cz@rock-chips.com>\r
+ *\r
+ * This program is the virtual flash device \r
+ * used to store bd_addr or MAC\r
+ *\r
+ */\r
+\r
+\r
+#include <linux/module.h>\r
+#include <linux/kernel.h>\r
+#include <linux/errno.h>\r
+#include <linux/miscdevice.h>\r
+#include <linux/fs.h>\r
+#include <linux/platform_device.h>\r
+#include <asm/uaccess.h>\r
+#include <asm/io.h>\r
+#include <linux/fs.h>\r
+#include <linux/slab.h>\r
+#include "eth_mac.h"\r
+\r
+#if 1\r
+#define DBG(x...) printk("eth_mac:" x)\r
+#else\r
+#define DBG(x...)\r
+#endif\r
+\r
+#define VERSION "0.1"\r
+\r
+#define WLAN_MAC_FILE "/data/misc/wifi/wlan_mac"\r
+\r
+extern char GetSNSectorInfo(char * pbuf);\r
+\r
+int eth_mac_read_from_IDB(u8 *mac)\r
+{\r
+ int i;\r
+ char *tempBuf = kmalloc(512, GFP_KERNEL);\r
+\r
+ if(mac == NULL)\r
+ return -EFAULT;\r
+\r
+ GetSNSectorInfo(tempBuf);\r
+#if 0\r
+ for (i = 0; i < 512; i++) {\r
+ printk("%02x, ", tempBuf[i]);\r
+ if(((i+1)%16) == 0) printk("\n");\r
+ }\r
+#endif\r
+ for (i = 506; i <= 511; i++) {\r
+ mac[i-506] = tempBuf[i];\r
+ }\r
+\r
+ kfree(tempBuf);\r
+\r
+ return 0;\r
+}\r
+\r
+int eth_mac_idb(u8 *eth_mac)\r
+{\r
+ int i;\r
+ int err = 0;\r
+ memset(eth_mac, 0, 6);\r
+ err = eth_mac_read_from_IDB(eth_mac);\r
+ if (err)\r
+ return -1;\r
+ printk("Read the Ethernet MAC address from IDB:");\r
+ for (i = 0; i < 5; i++)\r
+ printk("%2.2x:", eth_mac[i]);\r
+ printk("%2.2x\n", eth_mac[i]);\r
+\r
+ return 0;\r
+}\r
+\r
+#if 0\r
+/**\r
+*大写转小写\r
+*\r
+*/\r
+static void to_lower(char *str) \r
+{ \r
+ int i=0; \r
+ while(str[i]!=0) \r
+ { \r
+ if((str[i] >= 'A')&&(str[i] <= 'Z')) \r
+ str[i]+=32; \r
+ i++; \r
+ } \r
+} \r
+\r
+/**\r
+ *字符串格式转为mac 格式.\r
+ *\r
+ *\r
+ */\r
+static void trans( char *src ,int * k) \r
+{\r
+ char c;\r
+ int i;\r
+ int temp;\r
+ int temp2;\r
+\r
+ if( (src == NULL) ||(strlen(src) <16 ) ) // 参数检查\r
+ {\r
+ printk( "Arg Error\n" );\r
+ return ;\r
+ }\r
+\r
+ for( i = 0; i < 6; i++ )\r
+ {\r
+ temp = 0;\r
+ temp2 = 0;\r
+ c = *src;\r
+ if( c == ':' ){\r
+ src++;\r
+ c = *src;\r
+ }\r
+ if( c >= 'a' && c <= 'f' ) // 两个字符中的第一个 比如 "0f" ,则表示是字符 '0'\r
+ temp = ( c - 'a' ) + 10; \r
+ else\r
+ temp = ( c - '0' ) ;\r
+ src++;\r
+ \r
+ c = *src;\r
+ if( i == 5){ //wifi mac 末尾加1\r
+ if(c =='f'){\r
+ c = '0';\r
+ } if (c == '9'){\r
+ c = 'a';\r
+ }else{\r
+ c = c + 1;\r
+ }\r
+ }\r
+ if( c >= 'a' && c <= 'f' ) // 两个字符中的第二个,如 "f8" ,那么表示字符 '8'\r
+ temp2 = ( c - 'a' ) + 10;\r
+ else\r
+ temp2 = ( c - '0' ) ;\r
+\r
+ temp = temp * 16;\r
+ temp += temp2;\r
+ src++;\r
+ *(k+i) = temp;\r
+\r
+ }\r
+\r
+}\r
+\r
+int eth_mac_wifi(u8 *eth_mac){\r
+ int i;\r
+ struct file *file = NULL;\r
+ char wifi_mac[32];\r
+ mm_segment_t old_fs;\r
+ ssize_t ret;\r
+ int maci[6];\r
+\r
+ memset(eth_mac, 0, 6);\r
+ \r
+ file = filp_open(WLAN_MAC_FILE, O_RDWR,0);\r
+ if (IS_ERR(file))\r
+ {\r
+ printk("open %s failed.", WLAN_MAC_FILE);\r
+ return -ENOENT;\r
+ } \r
+\r
+ old_fs = get_fs();\r
+ set_fs(get_ds());\r
+ \r
+ file->f_op->llseek(file,0,0);\r
+ ret = file->f_op->read(file, wifi_mac, 32, &file->f_pos);\r
+ \r
+ set_fs(old_fs);\r
+ \r
+ if(ret > 0){\r
+ //printk("mac read from %s: %s\n", WLAN_MAC_FILE,wifi_mac);\r
+\r
+ to_lower(wifi_mac);\r
+ trans(wifi_mac,maci);\r
+ for (i = 0;i< 6;i++){\r
+ eth_mac[i] = maci[i];\r
+ }\r
+ \r
+ }\r
+ else if(ret == 0)\r
+ printk("read nothing from %s........\n",WLAN_MAC_FILE);\r
+ else \r
+ {\r
+ printk("read wifi mac error\n");\r
+ return -ENOENT;\r
+ }\r
+\r
+ filp_close(file,NULL);\r
+ return 0;\r
+ \r
+}\r
+\r
+#endif\r