Merge branch 'linux-linaro-lsk-v4.4-android' of git://git.linaro.org/kernel/linux...
[firefly-linux-kernel-4.4.55.git] / drivers / bluetooth / vflash.c
index 8be5c1bfa600e3561bf5c3ca554dd3be259d3b68..bb37c739571860becfe89a706b3e54a44890dec7 100755 (executable)
@@ -14,6 +14,7 @@
 #include <linux/miscdevice.h>\r
 #include <linux/fs.h>\r
 #include <linux/platform_device.h>\r
+#include <linux/slab.h>\r
 #include <asm/uaccess.h>\r
 \r
 #if 0\r
@@ -31,12 +32,12 @@ static struct miscdevice vflash_miscdev;
 #define READ_BDADDR_FROM_FLASH  0x01\r
 \r
 extern char GetSNSectorInfo(char * pbuf);\r
+extern unsigned char wlan_mac_addr[6];\r
 \r
-static int vflash_ioctl(struct inode *inode, struct file *file,\r
+static long vflash_ioctl(struct file *file,\r
                                        unsigned int cmd, unsigned long arg)\r
 {\r
        void __user *argp = (void __user *)arg;\r
-    unsigned long n = 0;\r
     \r
     DBG("%s---cmd=0x%x---arg=0x%x\n", __FUNCTION__, cmd, arg);\r
 \r
@@ -47,32 +48,59 @@ static int vflash_ioctl(struct inode *inode, struct file *file,
     {\r
         case READ_BDADDR_FROM_FLASH:\r
         {   \r
+#ifdef CONFIG_WIFI_MAC\r
+            unsigned char bd_addr[6] = {0};\r
+            int i;\r
+\r
+            printk("vflash: wlan_mac_addr:%X:%X:%X:%x:%X:%x\n", wlan_mac_addr[0],\r
+                                                wlan_mac_addr[1],\r
+                                                wlan_mac_addr[2],\r
+                                                wlan_mac_addr[3],\r
+                                                wlan_mac_addr[4],\r
+                                                wlan_mac_addr[5] );\r
+            for (i=1; i<6; i++) {\r
+                bd_addr[i] = wlan_mac_addr[5-i];\r
+            }\r
+\r
+            bd_addr[0] = wlan_mac_addr[5]+1;\r
+\r
+            printk("vflash: bd_addr:%X:%X:%X:%x:%X:%x\n", bd_addr[5],\r
+                                                bd_addr[4],\r
+                                                bd_addr[3],\r
+                                                bd_addr[2],\r
+                                                bd_addr[1],\r
+                                                bd_addr[0] );\r
+\r
+\r
+            if(copy_to_user(argp, bd_addr, 6)) {\r
+                printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
+                return -EFAULT;\r
+            }\r
+#else\r
             char *tempBuf = (char *)kmalloc(512, GFP_KERNEL);\r
+           char bd_addr[7] = {0};\r
             int i;\r
-            #if 0\r
+\r
             GetSNSectorInfo(tempBuf);\r
-            #else\r
-            tempBuf[498] = 0x00;\r
-            tempBuf[499] = 0x11;\r
-            tempBuf[500] = 0x22;\r
-            tempBuf[501] = 0x33;\r
-            tempBuf[502] = 0x44;\r
-            tempBuf[503] = 0x55;\r
-            tempBuf[504] = 0x66;\r
-            #endif\r
+\r
             for(i=498; i<=504; i++)\r
             {\r
                 DBG("tempBuf[%d]=%x\n", i, tempBuf[i]);\r
+               bd_addr[504-i] = tempBuf[i];\r
             }\r
+\r
             \r
-                       if(copy_to_user(argp, &(tempBuf[499]), 6))\r
-                       {\r
-                           printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
+            //printk("%s: ====> get bt addr from flash=[%02x:%02x:%02x:%02x:%02x:%02x]\n", __FUNCTION__,\r
+            //      bd_addr[5], bd_addr[4], bd_addr[3], bd_addr[2], bd_addr[1], bd_addr[0]);\r
+           if(copy_to_user(argp, bd_addr, 6))\r
+            {\r
+                printk("ERROR: copy_to_user---%s\n", __FUNCTION__);\r
                 kfree(tempBuf);\r
-                           return -EFAULT;\r
+                return -EFAULT;\r
             }\r
             \r
             kfree(tempBuf);\r
+#endif\r
         }\r
         break;\r
         default:\r
@@ -97,7 +125,7 @@ static int vflash_release(struct inode *inode, struct file *file)
 \r
 static const struct file_operations vflash_fops = {\r
        .owner          = THIS_MODULE,\r
-       .ioctl          = vflash_ioctl,\r
+       .unlocked_ioctl = vflash_ioctl,\r
        .open           = vflash_open,\r
        .release        = vflash_release,\r
 };\r