UPSTREAM: pwm: Get rid of pwm->lock
[firefly-linux-kernel-4.4.55.git] / drivers / bluetooth / rtk_btusb.h
1 /*
2  *
3  *  Realtek Bluetooth USB driver
4  *
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21 #include <linux/interrupt.h>
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/types.h>
25 #include <linux/sched.h>
26 #include <linux/skbuff.h>
27 #include <linux/errno.h>
28 #include <linux/usb.h>
29 #include <linux/cdev.h>
30 #include <linux/device.h>
31 #include <linux/poll.h>
32
33 #include <linux/version.h>
34 #include <linux/pm_runtime.h>
35 #include <linux/firmware.h>
36 #include <linux/suspend.h>
37
38 #define CONFIG_BLUEDROID        1 /* bleuz 0, bluedroid 1 */
39
40
41 /* Some Android system may use standard Linux kernel, while
42  * standard Linux may also implement early suspend feature.
43  * So exclude earysuspend.h from CONFIG_BLUEDROID.
44  */
45 #ifdef CONFIG_HAS_EARLYSUSPEND
46 #include <linux/earlysuspend.h>
47 #endif
48
49 #if CONFIG_BLUEDROID
50 #else
51 #include <net/bluetooth/bluetooth.h>
52 #include <net/bluetooth/hci_core.h>
53 #include <net/bluetooth/hci.h>
54 #endif
55
56
57 /***********************************
58 ** Realtek - For rtk_btusb driver **
59 ***********************************/
60 #define URB_CANCELING_DELAY_MS          10
61 /* when OS suspended, module is still powered,usb is not powered,
62  * this may set to 1, and must comply with special patch code.
63  */
64 #define CONFIG_RESET_RESUME     1
65 #define PRINT_CMD_EVENT         0
66 #define PRINT_ACL_DATA          0
67 #define PRINT_SCO_DATA          0
68
69 #define RTKBT_DBG_FLAG          0
70
71 #if RTKBT_DBG_FLAG
72 #define RTKBT_DBG(fmt, arg...) printk(KERN_INFO "rtk_btusb: " fmt "\n" , ## arg)
73 #else
74 #define RTKBT_DBG(fmt, arg...)
75 #endif
76 #define RTKBT_INFO(fmt, arg...) printk(KERN_INFO "rtk_btusb: " fmt "\n" , ## arg)
77 #define RTKBT_WARN(fmt, arg...) printk(KERN_WARNING "rtk_btusb: " fmt "\n" , ## arg)
78 #define RTKBT_ERR(fmt, arg...) printk(KERN_ERR "rtk_btusb: " fmt "\n" , ## arg)
79
80
81 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 33)
82 #define HDEV_BUS        hdev->bus
83 #define USB_RPM            1
84 #else
85 #define HDEV_BUS        hdev->type
86 #define USB_RPM            0
87 #endif
88
89 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 38)
90 #define NUM_REASSEMBLY 3
91 #endif
92
93 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 4, 0)
94 #define GET_DRV_DATA(x)        hci_get_drvdata(x)
95 #else
96 #define GET_DRV_DATA(x)        x->driver_data
97 #endif
98
99 #define SCO_NUM    hdev->conn_hash.sco_num
100
101
102 #define BTUSB_RPM        (0 * USB_RPM) /* 1 SS enable; 0 SS disable */
103 #define BTUSB_WAKEUP_HOST        0    /* 1  enable; 0  disable */
104 #define BTUSB_MAX_ISOC_FRAMES    10
105 #define BTUSB_INTR_RUNNING        0
106 #define BTUSB_BULK_RUNNING        1
107 #define BTUSB_ISOC_RUNNING        2
108 #define BTUSB_SUSPENDING        3
109 #define BTUSB_DID_ISO_RESUME    4
110
111 #define HCI_CMD_READ_BD_ADDR 0x1009
112 #define HCI_VENDOR_CHANGE_BDRATE 0xfc17
113 #define HCI_VENDOR_READ_RTK_ROM_VERISION 0xfc6d
114 #define HCI_VENDOR_READ_LMP_VERISION 0x1001
115 #define HCI_VENDOR_FORCE_RESET_AND_PATCHABLE 0xfc66
116 #define HCI_VENDOR_RESET                       0x0C03
117 #define HCI_VENDOR_ADD_WAKE_UP_DEVICE       0xfc7b
118 #define HCI_VENDOR_REMOVE_WAKE_UP_DEVICE    0xfc7c
119 #define HCI_VENDOR_CLEAR_POWERON_LIST       0xfc7d
120
121 #define HCI_VENDOR_USB_DISC_HARDWARE_ERROR   0xFF
122
123 #define SET_WAKEUP_DEVICE_CONF      "/data/misc/bluedroid/rtkbt_wakeup_ble.conf"
124
125 #define DRV_NORMAL_MODE 0
126 #define DRV_MP_MODE 1
127 int mp_drv_mode = 0; /* 1 Mptool Fw; 0 Normal Fw */
128
129 #define ROM_LMP_NONE                0x0000
130 #define ROM_LMP_8723a               0x1200
131 #define ROM_LMP_8723b               0x8723
132 #define ROM_LMP_8821a               0X8821
133 #define ROM_LMP_8761a               0X8761
134 #define ROM_LMP_8703a               0x8723
135 #define ROM_LMP_8763a               0x8763
136 #define ROM_LMP_8703b               0x8703
137 #define ROM_LMP_8723c               0x8703
138 #define ROM_LMP_8822b               0x8822
139 #define ROM_LMP_8723d               0x8723
140 #define ROM_LMP_8821c               0x8821
141
142 /* signature: Realtek */
143 const uint8_t RTK_EPATCH_SIGNATURE[8] = {0x52,0x65,0x61,0x6C,0x74,0x65,0x63,0x68};
144 /* Extension Section IGNATURE:0x77FD0451 */
145 const uint8_t EXTENSION_SECTION_SIGNATURE[4] = {0x51,0x04,0xFD,0x77};
146
147 uint16_t project_id[] = {
148     ROM_LMP_8723a,
149     ROM_LMP_8723b,
150     ROM_LMP_8821a,
151     ROM_LMP_8761a,
152     ROM_LMP_8703a,
153     ROM_LMP_8763a,
154     ROM_LMP_8703b,
155     ROM_LMP_8723c,
156     ROM_LMP_8822b,
157     ROM_LMP_8723d,
158     ROM_LMP_8821c,
159     ROM_LMP_NONE
160 };
161 struct rtk_eversion_evt {
162     uint8_t status;
163     uint8_t version;
164 } __attribute__ ((packed));
165
166 /*modified by lamparten 1020*/
167 struct rtk_reset_evt {
168     uint8_t status;
169 } __attribute__ ((packed));
170 /*modified by lamparten 1020*/
171
172 struct rtk_localversion_evt {
173     uint8_t status;
174     uint8_t hci_version;
175     uint16_t hci_revision;
176     uint8_t lmp_version;
177     uint16_t lmp_manufacture;
178     uint16_t lmp_subversion;
179 } __attribute__ ((packed));
180
181 struct rtk_epatch_entry {
182     uint16_t chip_id;
183     uint16_t patch_length;
184     uint32_t start_offset;
185     uint32_t coex_version;
186     uint32_t svn_version;
187     uint32_t fw_version;
188 } __attribute__ ((packed));
189
190 struct rtk_epatch {
191     uint8_t signature[8];
192     uint32_t fw_version;
193     uint16_t number_of_total_patch;
194     struct rtk_epatch_entry entry[0];
195 } __attribute__ ((packed));
196
197 struct rtk_extension_entry {
198     uint8_t opcode;
199     uint8_t length;
200     uint8_t *data;
201 } __attribute__ ((packed));
202
203 struct rtk_bt_vendor_config_entry{
204     uint16_t offset;
205     uint8_t entry_len;
206     uint8_t entry_data[0];
207 } __attribute__ ((packed));
208
209 struct rtk_bt_vendor_config{
210     uint32_t signature;
211     uint16_t data_len;
212     struct rtk_bt_vendor_config_entry entry[0];
213 } __attribute__ ((packed));
214
215 /* Realtek - For rtk_btusb driver end */
216
217 #if CONFIG_BLUEDROID
218 #define QUEUE_SIZE 500
219
220 /***************************************
221 ** Realtek - Integrate from bluetooth.h **
222 *****************************************/
223 /* Reserv for core and drivers use */
224 #define BT_SKB_RESERVE    8
225
226 /* BD Address */
227 typedef struct {
228     __u8 b[6];
229 } __packed bdaddr_t;
230
231 /* Skb helpers */
232 struct bt_skb_cb {
233     __u8 pkt_type;
234     __u8 incoming;
235     __u16 expect;
236     __u16 tx_seq;
237     __u8 retries;
238     __u8 sar;
239     __u8 force_active;
240 };
241
242 #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
243
244 static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
245 {
246     struct sk_buff *skb;
247
248     if ((skb = alloc_skb(len + BT_SKB_RESERVE, how))) {
249         skb_reserve(skb, BT_SKB_RESERVE);
250         bt_cb(skb)->incoming  = 0;
251     }
252     return skb;
253 }
254 /* Realtek - Integrate from bluetooth.h end */
255
256 /***********************************
257 ** Realtek - Integrate from hci.h **
258 ***********************************/
259 #define HCI_MAX_ACL_SIZE    1024
260 #define HCI_MAX_SCO_SIZE    255
261 #define HCI_MAX_EVENT_SIZE    260
262 #define HCI_MAX_FRAME_SIZE    (HCI_MAX_ACL_SIZE + 4)
263
264 /* HCI bus types */
265 #define HCI_VIRTUAL    0
266 #define HCI_USB        1
267 #define HCI_PCCARD    2
268 #define HCI_UART    3
269 #define HCI_RS232    4
270 #define HCI_PCI        5
271 #define HCI_SDIO    6
272
273 /* HCI controller types */
274 #define HCI_BREDR    0x00
275 #define HCI_AMP        0x01
276
277 /* HCI device flags */
278 enum {
279     HCI_UP,
280     HCI_INIT,
281     HCI_RUNNING,
282
283     HCI_PSCAN,
284     HCI_ISCAN,
285     HCI_AUTH,
286     HCI_ENCRYPT,
287     HCI_INQUIRY,
288
289     HCI_RAW,
290
291     HCI_RESET,
292 };
293
294 /*
295  * BR/EDR and/or LE controller flags: the flags defined here should represent
296  * states from the controller.
297  */
298 enum {
299     HCI_SETUP,
300     HCI_AUTO_OFF,
301     HCI_MGMT,
302     HCI_PAIRABLE,
303     HCI_SERVICE_CACHE,
304     HCI_LINK_KEYS,
305     HCI_DEBUG_KEYS,
306     HCI_UNREGISTER,
307
308     HCI_LE_SCAN,
309     HCI_SSP_ENABLED,
310     HCI_HS_ENABLED,
311     HCI_LE_ENABLED,
312     HCI_CONNECTABLE,
313     HCI_DISCOVERABLE,
314     HCI_LINK_SECURITY,
315     HCI_PENDING_CLASS,
316 };
317
318 /* HCI data types */
319 #define HCI_COMMAND_PKT        0x01
320 #define HCI_ACLDATA_PKT        0x02
321 #define HCI_SCODATA_PKT        0x03
322 #define HCI_EVENT_PKT        0x04
323 #define HCI_VENDOR_PKT        0xff
324
325 #define HCI_MAX_NAME_LENGTH        248
326 #define HCI_MAX_EIR_LENGTH        240
327
328 #define HCI_OP_READ_LOCAL_VERSION    0x1001
329 struct hci_rp_read_local_version {
330     __u8     status;
331     __u8     hci_ver;
332     __le16   hci_rev;
333     __u8     lmp_ver;
334     __le16   manufacturer;
335     __le16   lmp_subver;
336 } __packed;
337
338 #define HCI_EV_CMD_COMPLETE        0x0e
339 struct hci_ev_cmd_complete {
340     __u8     ncmd;
341     __le16   opcode;
342 } __packed;
343
344 /* ---- HCI Packet structures ---- */
345 #define HCI_COMMAND_HDR_SIZE 3
346 #define HCI_EVENT_HDR_SIZE   2
347 #define HCI_ACL_HDR_SIZE     4
348 #define HCI_SCO_HDR_SIZE     3
349
350 struct hci_command_hdr {
351     __le16    opcode;        /* OCF & OGF */
352     __u8    plen;
353 } __packed;
354
355 struct hci_event_hdr {
356     __u8    evt;
357     __u8    plen;
358 } __packed;
359
360 struct hci_acl_hdr {
361     __le16    handle;        /* Handle & Flags(PB, BC) */
362     __le16    dlen;
363 } __packed;
364
365 struct hci_sco_hdr {
366     __le16    handle;
367     __u8    dlen;
368 } __packed;
369
370 static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb)
371 {
372     return (struct hci_event_hdr *) skb->data;
373 }
374
375 static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb)
376 {
377     return (struct hci_acl_hdr *) skb->data;
378 }
379
380 static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
381 {
382     return (struct hci_sco_hdr *) skb->data;
383 }
384
385 /* ---- HCI Ioctl requests structures ---- */
386 struct hci_dev_stats {
387     __u32 err_rx;
388     __u32 err_tx;
389     __u32 cmd_tx;
390     __u32 evt_rx;
391     __u32 acl_tx;
392     __u32 acl_rx;
393     __u32 sco_tx;
394     __u32 sco_rx;
395     __u32 byte_rx;
396     __u32 byte_tx;
397 };
398 /* Realtek - Integrate from hci.h end */
399
400 /*****************************************
401 ** Realtek - Integrate from hci_core.h  **
402 *****************************************/
403 struct hci_conn_hash {
404     struct list_head list;
405     unsigned int     acl_num;
406     unsigned int     sco_num;
407     unsigned int     le_num;
408 };
409
410 #define HCI_MAX_SHORT_NAME_LENGTH    10
411
412 #define NUM_REASSEMBLY 4
413 struct hci_dev {
414     struct mutex    lock;
415
416     char        name[8];
417     unsigned long    flags;
418     __u16        id;
419     __u8        bus;
420     __u8        dev_type;
421
422     struct sk_buff        *reassembly[NUM_REASSEMBLY];
423
424     struct hci_conn_hash    conn_hash;
425
426     struct hci_dev_stats    stat;
427
428 #if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 4, 0)
429     atomic_t        refcnt;
430     struct module           *owner;
431     void                    *driver_data;
432 #endif
433
434     atomic_t        promisc;
435
436     struct device        *parent;
437     struct device        dev;
438
439     unsigned long        dev_flags;
440
441     int (*open)(struct hci_dev *hdev);
442     int (*close)(struct hci_dev *hdev);
443     int (*flush)(struct hci_dev *hdev);
444     int (*send)(struct sk_buff *skb);
445 #if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 4, 0)
446     void (*destruct)(struct hci_dev *hdev);
447 #endif
448 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 7, 1)
449     __u16               voice_setting;
450 #endif
451     void (*notify)(struct hci_dev *hdev, unsigned int evt);
452     int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
453 };
454
455 #if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 4, 0)
456 static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
457 {
458     atomic_inc(&d->refcnt);
459     return d;
460 }
461
462 static inline void __hci_dev_put(struct hci_dev *d)
463 {
464     if (atomic_dec_and_test(&d->refcnt))
465         d->destruct(d);
466 }
467 #endif
468
469 static inline void *hci_get_drvdata(struct hci_dev *hdev)
470 {
471     return dev_get_drvdata(&hdev->dev);
472 }
473
474 static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
475 {
476     dev_set_drvdata(&hdev->dev, data);
477 }
478
479 #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
480 /* Realtek - Integrate from hci_core.h end */
481
482 /* -----  HCI Commands ---- */
483 #define HCI_OP_INQUIRY            0x0401
484 #define HCI_OP_INQUIRY_CANCEL        0x0402
485 #define HCI_OP_EXIT_PERIODIC_INQ    0x0404
486 #define HCI_OP_CREATE_CONN        0x0405
487 #define HCI_OP_DISCONNECT                0x0406
488 #define HCI_OP_ADD_SCO            0x0407
489 #define HCI_OP_CREATE_CONN_CANCEL    0x0408
490 #define HCI_OP_ACCEPT_CONN_REQ        0x0409
491 #define HCI_OP_REJECT_CONN_REQ        0x040a
492 #define HCI_OP_LINK_KEY_REPLY        0x040b
493 #define HCI_OP_LINK_KEY_NEG_REPLY    0x040c
494 #define HCI_OP_PIN_CODE_REPLY        0x040d
495 #define HCI_OP_PIN_CODE_NEG_REPLY    0x040e
496 #define HCI_OP_CHANGE_CONN_PTYPE    0x040f
497 #define HCI_OP_AUTH_REQUESTED        0x0411
498 #define HCI_OP_SET_CONN_ENCRYPT        0x0413
499 #define HCI_OP_CHANGE_CONN_LINK_KEY    0x0415
500 #define HCI_OP_REMOTE_NAME_REQ        0x0419
501 #define HCI_OP_REMOTE_NAME_REQ_CANCEL    0x041a
502 #define HCI_OP_READ_REMOTE_FEATURES    0x041b
503 #define HCI_OP_READ_REMOTE_EXT_FEATURES    0x041c
504 #define HCI_OP_READ_REMOTE_VERSION    0x041d
505 #define HCI_OP_SETUP_SYNC_CONN        0x0428
506 #define HCI_OP_ACCEPT_SYNC_CONN_REQ    0x0429
507 #define HCI_OP_REJECT_SYNC_CONN_REQ    0x042a
508 #define HCI_OP_SNIFF_MODE        0x0803
509 #define HCI_OP_EXIT_SNIFF_MODE        0x0804
510 #define HCI_OP_ROLE_DISCOVERY        0x0809
511 #define HCI_OP_SWITCH_ROLE        0x080b
512 #define HCI_OP_READ_LINK_POLICY        0x080c
513 #define HCI_OP_WRITE_LINK_POLICY    0x080d
514 #define HCI_OP_READ_DEF_LINK_POLICY    0x080e
515 #define HCI_OP_WRITE_DEF_LINK_POLICY    0x080f
516 #define HCI_OP_SNIFF_SUBRATE        0x0811
517 #define HCI_OP_SET_EVENT_MASK        0x0c01
518 #define HCI_OP_RESET            0x0c03
519 #define HCI_OP_SET_EVENT_FLT        0x0c05
520 #define HCI_OP_Write_Extended_Inquiry_Response        0x0c52
521
522 /* -----  HCI events---- */
523 #define HCI_OP_DISCONNECT        0x0406
524 #define HCI_EV_INQUIRY_COMPLETE        0x01
525 #define HCI_EV_INQUIRY_RESULT        0x02
526 #define HCI_EV_CONN_COMPLETE        0x03
527 #define HCI_EV_CONN_REQUEST            0x04
528 #define HCI_EV_DISCONN_COMPLETE        0x05
529 #define HCI_EV_AUTH_COMPLETE        0x06
530 #define HCI_EV_REMOTE_NAME            0x07
531 #define HCI_EV_ENCRYPT_CHANGE        0x08
532 #define HCI_EV_CHANGE_LINK_KEY_COMPLETE    0x09
533
534 #define HCI_EV_REMOTE_FEATURES        0x0b
535 #define HCI_EV_REMOTE_VERSION        0x0c
536 #define HCI_EV_QOS_SETUP_COMPLETE    0x0d
537 #define HCI_EV_CMD_COMPLETE            0x0e
538 #define HCI_EV_CMD_STATUS            0x0f
539
540 #define HCI_EV_ROLE_CHANGE            0x12
541 #define HCI_EV_NUM_COMP_PKTS        0x13
542 #define HCI_EV_MODE_CHANGE            0x14
543 #define HCI_EV_PIN_CODE_REQ            0x16
544 #define HCI_EV_LINK_KEY_REQ            0x17
545 #define HCI_EV_LINK_KEY_NOTIFY        0x18
546 #define HCI_EV_CLOCK_OFFSET            0x1c
547 #define HCI_EV_PKT_TYPE_CHANGE        0x1d
548 #define HCI_EV_PSCAN_REP_MODE        0x20
549
550 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI    0x22
551 #define HCI_EV_REMOTE_EXT_FEATURES    0x23
552 #define HCI_EV_SYNC_CONN_COMPLETE    0x2c
553 #define HCI_EV_SYNC_CONN_CHANGED    0x2d
554 #define HCI_EV_SNIFF_SUBRATE            0x2e
555 #define HCI_EV_EXTENDED_INQUIRY_RESULT    0x2f
556 #define HCI_EV_IO_CAPA_REQUEST        0x31
557 #define HCI_EV_SIMPLE_PAIR_COMPLETE    0x36
558 #define HCI_EV_REMOTE_HOST_FEATURES    0x3d
559
560 #define CONFIG_MAC_OFFSET_GEN_1_2       (0x3C)      //MAC's OFFSET in config/efuse for realtek generation 1~2 bluetooth chip
561 #define CONFIG_MAC_OFFSET_GEN_3PLUS     (0x44)      //MAC's OFFSET in config/efuse for rtk generation 3+ bluetooth chip
562
563 /*******************************
564 **    Reasil patch code
565 ********************************/
566 #define CMD_CMP_EVT        0x0e
567 #define PKT_LEN            300
568 #define MSG_TO            1000
569 #define PATCH_SEG_MAX    252
570 #define DATA_END        0x80
571 #define DOWNLOAD_OPCODE    0xfc20
572 #define BTOFF_OPCODE    0xfc28
573 #define TRUE            1
574 #define FALSE            0
575 #define CMD_HDR_LEN        sizeof(struct hci_command_hdr)
576 #define EVT_HDR_LEN        sizeof(struct hci_event_hdr)
577 #define CMD_CMP_LEN        sizeof(struct hci_ev_cmd_complete)
578 #define MAX_PATCH_SIZE_24K (1024*24)
579 #define MAX_PATCH_SIZE_40K (1024*40)
580
581 enum rtk_endpoit {
582     CTRL_EP = 0,
583     INTR_EP = 1,
584     BULK_EP = 2,
585     ISOC_EP = 3
586 };
587
588 typedef struct {
589     uint16_t    vid;
590     uint16_t    pid;
591     uint16_t    lmp_sub_default;
592     uint16_t    lmp_sub;
593     uint16_t    eversion;
594     char        *mp_patch_name;
595     char        *patch_name;
596     char        *config_name;
597     uint8_t     *fw_cache;
598     int         fw_len;
599     uint16_t    mac_offset;
600     uint32_t    max_patch_size;
601 } patch_info;
602
603 typedef struct {
604     struct usb_interface    *intf;
605     struct usb_device        *udev;
606     patch_info *patch_entry;
607     int            pipe_in, pipe_out;
608     uint8_t        *send_pkt;
609     uint8_t        *rcv_pkt;
610     struct hci_command_hdr        *cmd_hdr;
611     struct hci_event_hdr        *evt_hdr;
612     struct hci_ev_cmd_complete    *cmd_cmp;
613     uint8_t        *req_para,    *rsp_para;
614     uint8_t        *fw_data;
615     int            pkt_len;
616     int            fw_len;
617 } firmware_info;
618
619 typedef struct {
620     uint8_t index;
621     uint8_t data[PATCH_SEG_MAX];
622 } __attribute__((packed)) download_cp;
623
624 typedef struct {
625     uint8_t status;
626     uint8_t index;
627 } __attribute__((packed)) download_rp;
628
629
630
631 //Define ioctl cmd the same as HCIDEVUP in the kernel
632 #define DOWN_FW_CFG  _IOW('H', 201, int)
633
634
635 /*  for altsettings*/
636 #include <linux/fs.h>
637 #define BDADDR_FILE "/data/misc/bluetooth/bdaddr"
638 #define FACTORY_BT_BDADDR_STORAGE_LEN 17
639
640 static inline int getmacaddr(uint8_t * vnd_local_bd_addr)
641 {
642     struct file  *bdaddr_file;
643     mm_segment_t oldfs;
644     char buf[FACTORY_BT_BDADDR_STORAGE_LEN];
645     int32_t i = 0;
646     memset(buf, 0, FACTORY_BT_BDADDR_STORAGE_LEN);
647     bdaddr_file = filp_open(BDADDR_FILE, O_RDONLY, 0);
648     if (IS_ERR(bdaddr_file)){
649         RTKBT_INFO("No Mac Config for BT\n");
650         return -1;
651     }
652     oldfs = get_fs(); set_fs(KERNEL_DS);
653     bdaddr_file->f_op->llseek(bdaddr_file, 0, 0);
654     bdaddr_file->f_op->read(bdaddr_file, buf, FACTORY_BT_BDADDR_STORAGE_LEN, &bdaddr_file->f_pos);
655     for (i = 0; i < 6; i++) {
656      if(buf[3*i]>'9')
657      {
658          if(buf[3*i]>'Z')
659               buf[3*i] -=('a'-'A'); //change  a to A
660          buf[3*i] -= ('A'-'9'-1);
661      }
662      if(buf[3*i+1]>'9')
663      {
664         if(buf[3*i+1]>'Z')
665               buf[3*i+1] -=('a'-'A'); //change  a to A
666          buf[3*i+1] -= ('A'-'9'-1);
667      }
668      vnd_local_bd_addr[5-i] = ((uint8_t)buf[3*i]-'0')*16 + ((uint8_t)buf[3*i+1]-'0');
669     }
670     set_fs(oldfs);
671     filp_close(bdaddr_file, NULL);
672     return 0;
673 }
674
675 static inline int getAltSettings(patch_info *patch_entry, unsigned short *offset, int max_group_cnt)
676 {
677     int n = 0;
678     if(patch_entry)
679         offset[n++] = patch_entry->mac_offset;
680 /*
681 //sample code, add special settings
682
683     offset[n++] = 0x15B;
684 */
685     return n;
686 }
687 static inline int getAltSettingVal(patch_info *patch_entry, unsigned short offset, unsigned char * val)
688 {
689     int res = 0;
690
691     switch(offset)
692     {
693 /*
694 //sample code, add special settings
695         case 0x15B:
696             val[0] = 0x0B;
697             val[1] = 0x0B;
698             val[2] = 0x0B;
699             val[3] = 0x0B;
700             res = 4;
701             break;
702 */
703         default:
704             res = 0;
705             break;
706     }
707
708     if((patch_entry)&&(offset == patch_entry->mac_offset)&&(res == 0))
709     {
710         if(getmacaddr(val) == 0){
711             RTKBT_INFO("MAC: %02x:%02x:%02x:%02x:%02x:%02x", val[5], val[4], val[3], val[2], val[1], val[0]);
712             res = 6;
713         }
714     }
715     return res;
716 }
717
718 #endif /* CONFIG_BLUEDROID */