summaryrefslogtreecommitdiffstats
path: root/fm_hci/fm_hci.cpp
blob: 76949d2032578495e04b77cfd231a2d6ee9d0fd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/*
 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *        * Redistributions of source code must retain the above copyright
 *            notice, this list of conditions and the following disclaimer.
 *        * Redistributions in binary form must reproduce the above
 *            copyright notice, this list of conditions and the following
 *            disclaimer in the documentation and/or other materials provided
 *            with the distribution.
 *        * Neither the name of The Linux Foundation nor the names of its
 *            contributors may be used to endorse or promote products derived
 *            from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*****************************************************************************
 *
 *  This file contains main functions to support FM HCI interface to send
 *  commands and  recieved events.
 *
 *****************************************************************************/

#define LOG_TAG "fm_hci"

#include <queue>          // std::queue
#include <mutex>              // std::mutex, std::unique_lock
#include <condition_variable> // std::condition_variable
#include <cstdlib>
#include <thread>

#include <utils/Log.h>
#include <unistd.h>

#include <vendor/qti/hardware/fm/1.0/IFmHci.h>
#include <vendor/qti/hardware/fm/1.0/IFmHciCallbacks.h>
#include <vendor/qti/hardware/fm/1.0/types.h>
#include "fm_hci.h"

#include <hwbinder/ProcessState.h>

using vendor::qti::hardware::fm::V1_0::IFmHci;
using vendor::qti::hardware::fm::V1_0::IFmHciCallbacks;
using vendor::qti::hardware::fm::V1_0::HciPacket;
using vendor::qti::hardware::fm::V1_0::Status;
using android::hardware::ProcessState;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::hidl_vec;

static struct fm_hci_t hci;

typedef std::unique_lock<std::mutex> Lock;
android::sp<IFmHci> fmHci;

static int enqueue_fm_rx_event(struct fm_event_header_t *hdr);
static void dequeue_fm_rx_event();
static int enqueue_fm_tx_cmd(struct fm_command_header_t *hdr);
static void dequeue_fm_tx_cmd();
static void  hci_tx_thread();
static void hci_rx_thread();
static int start_tx_thread();
static void stop_tx_thread();
static int start_rx_thread();
static void stop_rx_thread();
static void cleanup_threads();
static bool hci_initialize();
static void hci_transmit(struct fm_command_header_t *hdr);
static void hci_close();

/*******************************************************************************
**
** Function         enqueue_fm_rx_event
**
** Description      This function is called in the hal daemon context to queue
**                  FM events in RX queue.
**
** Parameters:      hdr - contains the fm event header pointer
**
**
** Returns          int
**
*******************************************************************************/
static int enqueue_fm_rx_event(struct fm_event_header_t *hdr)
{

    ALOGI("%s: putting lock before enqueue ", __func__);
    hci.rx_cond_mtx.lock();
    hci.rx_event_queue.push(hdr);
    hci.rx_cond_mtx.unlock();
    ALOGI("%s:notify to waiting thred", __func__);
    hci.rx_cond.notify_all();
    ALOGI("%s: FM-Event ENQUEUED SUCCESSFULLY", __func__);

    return FM_HC_STATUS_SUCCESS;
}

/*******************************************************************************
**
** Function         dequeue_fm_rx_event
**
** Description      This function is called in the rx thread context to dequeue
**                  FM events from RX queue & processing the FM event.
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void dequeue_fm_rx_event()
{
    fm_event_header_t *evt_buf;

    ALOGI("%s", __func__);
    while (1) {
        if (hci.rx_event_queue.empty()) {
            ALOGI("No more FM Events are available in the RX Queue");
            return;
        } else {
        }

        evt_buf = hci.rx_event_queue.front();
        hci.rx_event_queue.pop();

        if (evt_buf->evt_code == FM_CMD_COMPLETE) {
            ALOGI("%s: FM_CMD_COMPLETE: current_credits %d, %d Credits got from the SOC", __func__, hci.command_credits, evt_buf->params[0]);
            if (hci.command_credits == 0) {
                hci.command_credits += evt_buf->params[0];
                ALOGI(" dequeue_fm_rx_event: wait for tx_cond_lock ");
                hci.tx_cond_mtx.lock();
                ALOGI(" dequeue_fm_rx_event: Notifying tx_cond_lock ");
                hci.tx_cond.notify_all();
                ALOGI(" dequeue_fm_rx_event: UNLOCKING tx_cond_lock ");
                hci.tx_cond_mtx.unlock();
            } else {
                hci.command_credits += evt_buf->params[0];
            }

        } else if (evt_buf->evt_code == FM_CMD_STATUS) {
            ALOGI("%s: FM_CMD_STATUS: current_credits %d, %d Credits got from the SOC", __func__, hci.command_credits, evt_buf->params[1]);
            if (hci.command_credits == 0) {
                hci.command_credits += evt_buf->params[1];
                ALOGI(" dequeue_fm_rx_event: wait for tx_cond_lock ");
                hci.tx_cond_mtx.lock();
                ALOGI(" dequeue_fm_rx_event: Notifying tx_cond_lock ");
                hci.tx_cond.notify_all();
                ALOGI(" dequeue_fm_rx_event: UNLOCKING tx_cond_lock ");
                hci.tx_cond_mtx.unlock();
            } else {
                hci.command_credits += evt_buf->params[1];
            }
        } else if (evt_buf->evt_code == FM_HW_ERR_EVENT) {
            ALOGI("%s: FM H/w Err Event Recvd. Event Code: 0x%x", __func__, evt_buf->evt_code);
        } else {
            ALOGE("%s: Not CS/CC Event: Recvd. Event Code: 0x%x", __func__, evt_buf->evt_code);
        }

        if (hci.cb && hci.cb->process_event) {
            ALOGI("%s: processing the event", __func__);
            hci.cb->process_event(NULL, (uint8_t *)evt_buf);
        }

        free(evt_buf);
        evt_buf = NULL;
    }

}

/*******************************************************************************
**
** Function         enqueue_fm_tx_cmd
**
** Description      This function is called in the application JNI context to
**                  queue FM commands in TX queue.
**
** Parameters:      hdr - contains the fm command header pointer
**
**
** Returns          int
**
*******************************************************************************/
static int enqueue_fm_tx_cmd(struct fm_command_header_t *hdr)
{
    ALOGI("%s:  opcode 0x%x len:%d ", __func__,  hdr->opcode, hdr->len);

    hci.tx_queue_mtx.lock();
    hci.tx_cmd_queue.push(hdr);
    hci.tx_queue_mtx.unlock();

    ALOGI("%s:  notifying credits %d", __func__, hci.command_credits);
    if (hci.command_credits > 0) {
        ALOGI(" enqueue_fm_tx_cmd: wait for tx_cond_lock ");
        hci.tx_cond_mtx.lock();
        ALOGI(" enqueue_fm_tx_cmd: Notifying tx_cond_lock ");
        hci.tx_cond.notify_all();
        ALOGI(" enqueue_fm_tx_cmd: UNLOCK tx_cond_lock ");
        hci.tx_cond_mtx.unlock();
    }

    ALOGI("%s: FM-CMD ENQUEUED SUCCESSFULLY  credits %d", __func__, hci.command_credits);

    return FM_HC_STATUS_SUCCESS;
}

/*******************************************************************************
**
** Function         dequeue_fm_tx_cmd
**
** Description      This function is called in the tx thread context to dequeue
**                  & transmitting FM command to to HAL daemon.
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void dequeue_fm_tx_cmd()
{
    fm_command_header_t *hdr;

    ALOGI("%s", __func__);

    while (1) 
    {
       ALOGI(" dequeue_fm_tx_cmd:  command credits %d ", hci.command_credits);
       if (hci.command_credits == 0) {
          return;
       }
        hci.tx_queue_mtx.lock();
        ALOGI("%s is_que_empty %d", __func__,hci.tx_cmd_queue.empty());
        if(hci.tx_cmd_queue.empty()){
            ALOGI(" %s No more FM CMDs are available in the Queue",__func__);
            hci.tx_queue_mtx.unlock();
            return;
        }

        hdr = hci.tx_cmd_queue.front();
        hci.tx_cmd_queue.pop();
        hci.tx_queue_mtx.unlock();
        ALOGI("%s: packet popped %d credits", __func__,hci.command_credits);


        hci.command_credits--;
        hci_transmit(hdr);
        ALOGI("%s: packet transmitted %d credits", __func__,hci.command_credits);
    }
    ALOGI(" %s outside while(1), credits %d ", __func__, hci.command_credits);
}


/*******************************************************************************
**
** Function         hci_tx_thread
**
** Description      This function is main function of tx worker thread.
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void  hci_tx_thread()
{
    ALOGI("%s: ##### starting hci_tx_thread Worker thread!!! #####", __func__);
    hci.is_tx_thread_running = true;

    Lock lk(hci.tx_cond_mtx);
    while (hci.state != FM_RADIO_DISABLING && hci.state != FM_RADIO_DISABLED) {
        //wait  for tx cmd
        ALOGI("%s: before wait %d credits!!!" , __func__,hci.command_credits);
        hci.tx_cond.wait(lk);
        ALOGV("%s: after wait dequeueing the tx cmd!!!" , __func__);
        dequeue_fm_tx_cmd();
    }

    hci.is_tx_thread_running =false;
    ALOGI("%s: ##### Exiting hci_tx_thread Worker thread!!! #####", __func__);
}

/*******************************************************************************
**
** Function         hci_rx_thread
**
** Description      This function is main function of tx worker thread.
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void hci_rx_thread()
{

    ALOGI("%s: ##### starting hci_rx_thread Worker thread!!! #####", __func__);
    hci.is_rx_thread_running = true;

    ALOGI("%s: constr unique_lock ", __func__);
    Lock lk(hci.rx_cond_mtx);
    while (hci.state != FM_RADIO_DISABLING && hci.state != FM_RADIO_DISABLED) {
        //wait for rx event
        ALOGI("%s:before wait", __func__);
        hci.rx_cond.wait(lk);
        ALOGI("%s:after wait ", __func__);
        dequeue_fm_rx_event();
    }

    hci.is_rx_thread_running = false;
    ALOGI("%s: ##### Exiting hci_rx_thread Worker thread!!! #####", __func__);
}

/*******************************************************************************
**
** Function         start_tx_thread
**
** Description      This function is called to start tx worker thread.
**
** Parameters:      void
**
**
** Returns          int
**
*******************************************************************************/
static int start_tx_thread()
{

    ALOGI("FM-HCI: Creating the FM-HCI  TX TASK...");
    hci.tx_thread_ = std::thread(hci_tx_thread);
    if (!hci.tx_thread_.joinable()) {
        ALOGE("tx thread is not joinable");
        return FM_HC_STATUS_FAIL;
    }

    return FM_HC_STATUS_SUCCESS;
}

/*******************************************************************************
**
** Function         stop_tx_thread
**
** Description      This function is called to stop tx worker thread.
**
** Parameters:      void
**
**
** Returns          int
**
*******************************************************************************/
static void stop_tx_thread()
{
    int ret;

    ALOGI("%s:stop_tx_thread ++", __func__);
    hci.tx_cond_mtx.lock();
    hci.tx_cond.notify_all();
    ALOGI("%s:notify to tx thread", __func__);
    hci.tx_cond_mtx.unlock();

    hci.tx_thread_.join();
    ALOGI("%s:stop_tx_thread --", __func__);
}

/*******************************************************************************
**
** Function         start_rx_thread
**
** Description      This function is called to start rx worker thread.
**
** Parameters:      void
**
**
** Returns          int
**
*******************************************************************************/
static int start_rx_thread()
{
    int ret = FM_HC_STATUS_SUCCESS;
    ALOGI("FM-HCI: Creating the FM-HCI RX TASK...");

    hci.rx_thread_ = std::thread(hci_rx_thread);
    if (!hci.rx_thread_.joinable()) {
        ALOGE("rx thread is not joinable");
        return FM_HC_STATUS_FAIL;
    }

    return ret;
}

/*******************************************************************************
**
** Function         stop_rx_thread
**
** Description      This function is called to stop rx worker thread.
**
** Parameters:      void
**
**
** Returns          int
**
*******************************************************************************/
static void stop_rx_thread()
{
    ALOGI("%s:stop_rx_thread ++", __func__);
    hci.rx_cond.notify_all();

    hci.rx_thread_.join();
    ALOGI("%s:stop_rx_thread --", __func__);
}

/*******************************************************************************
**
** Function         cleanup_threads
**
** Description      This function is called to cleanup rx & tx worker thread.
**
** Parameters:      void
**
**
** Returns          int
**
*******************************************************************************/
static void cleanup_threads()
{
    stop_rx_thread();
    stop_tx_thread();
}

/*******************************************************************************
**
** Function         initialization_complete
**
** Description      This function is called, when initialization complete
**                  callback is called by hal daemon.
**
** Parameters:      hdr - contains the fm event header pointer
**
**
** Returns          int
**
*******************************************************************************/
static void initialization_complete(bool is_hci_initialize)
{
    int ret;
    ALOGI("++%s: is_hci_initialize: %d", __func__, is_hci_initialize);

    while (is_hci_initialize) {
        ret = start_tx_thread();
        if (ret)
        {
            cleanup_threads();
            hci.state = FM_RADIO_DISABLING;
            break;
        }

        ret = start_rx_thread();
        if (ret)
        {
            cleanup_threads();
            hci.state = FM_RADIO_DISABLING;
            break;
        }

        hci.state = FM_RADIO_ENABLED;
        break;
    }

    hci.on_cond.notify_all();
    ALOGI("--%s: is_hci_initialize: %d", __func__, is_hci_initialize);

}

/*******************************************************************************
**
** Class            FmHciCallbacks
**
** Description      This is main class, which has the implemention for FM HCI
**                  callback functions.
**
** Member callback Functions:      initializationComplete, hciEventReceived
**
**
** Returns          int
**
*******************************************************************************/
class FmHciCallbacks : public IFmHciCallbacks {
    public:
        FmHciCallbacks() {
        };
        virtual ~FmHciCallbacks() = default;

        Return<void> initializationComplete(Status status) {
            if(status == Status::SUCCESS)
            {
                initialization_complete(true);
            } else {
                initialization_complete(false);
            }

            return Void();
        }

        Return<void> hciEventReceived(const hidl_vec<uint8_t>& event) {
            struct fm_event_header_t *temp = (struct fm_event_header_t *) malloc(event.size());
            if (temp != nullptr) {
                memcpy(temp, event.data(), event.size());
                ALOGI("%s: evt_code:  0x%x", __func__, temp->evt_code);
                enqueue_fm_rx_event(temp);
            } else {
                ALOGE("%s: Memory Allocation failed for event buffer ",__func__);
            }
            return Void();
        }
};

/*******************************************************************************
**
** Function         hci_initialize
**
** Description      This function is used to initialize fm hci hidl transport.
**                  It makes a binder call to hal daemon
**
** Parameters:      void
**
**
** Returns          bool
**
*******************************************************************************/
static bool hci_initialize()
{
    ALOGI("%s", __func__);

    fmHci = IFmHci::getService();

    if (fmHci != nullptr) {
        hci.state = FM_RADIO_ENABLING;
        android::sp<IFmHciCallbacks> callbacks = new FmHciCallbacks();
        auto hidl_daemon_status = fmHci->initialize(callbacks);
        if(!hidl_daemon_status.isOk()) {
            ALOGE("%s: HIDL daemon is dead", __func__);
        }
        return true;
    } else {
        return false;
    }
}

/*******************************************************************************
**
** Function         hci_transmit
**
** Description      This function is used to send fm command to fm hci hidl transport.
**                  It makes a binder call to hal daemon.
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void hci_transmit(struct fm_command_header_t *hdr) {
    HciPacket data;

    ALOGI("%s: opcode 0x%x len:%d", __func__, hdr->opcode, hdr->len);

    if (fmHci != nullptr) {
        data.setToExternal((uint8_t *)hdr, 3 + hdr->len);
        auto hidl_daemon_status = fmHci->sendHciCommand(data);
        if(!hidl_daemon_status.isOk()) {
            ALOGE("%s: send Command failed, HIDL daemon is dead", __func__);
        }
    } else {
        ALOGI("%s: fmHci is NULL", __func__);
    }

    free(hdr);
}

/*******************************************************************************
**
** Function         hci_close
**
** Description      This function is used to close fm hci hidl transport.
**                  It makes a binder call to hal daemon
**
** Parameters:      void
**
**
** Returns          void
**
*******************************************************************************/
static void hci_close()
{
    ALOGI("%s", __func__);

    if (fmHci != nullptr) {
        auto hidl_daemon_status = fmHci->close();
        if(!hidl_daemon_status.isOk()) {
            ALOGE("%s: HIDL daemon is dead", __func__);
        }
        fmHci = nullptr;
    }
}

/*******************************************************************************
**
** Function         fm_hci_init
**
** Description      This function is used to intialize fm hci
**
** Parameters:     hci_hal - contains the fm helium hal hci pointer
**
**
** Returns          void
**
*******************************************************************************/
int fm_hci_init(fm_hci_hal_t *hci_hal)
{
    int ret = FM_HC_STATUS_FAIL;

    ALOGD("++%s", __func__);

    if(hci.is_rx_thread_running)
    {
        ALOGI("%s:previous rx thread running wait until rx thread stops", __func__);
        hci.rx_thread_.join();
        ALOGI("%s:stop_rx_thread completed, proceed iniialization", __func__);
    }
    if (!hci_hal || !hci_hal->hal) {
        ALOGE("NULL input argument");
        return FM_HC_STATUS_NULL_POINTER;
    }

    memset(&hci, 0, sizeof(struct fm_hci_t));

    hci.cb = hci_hal->cb;
    hci.command_credits = 1;
    hci.is_tx_thread_running = false;
    hci.is_rx_thread_running = false;
    hci.state = FM_RADIO_DISABLED;
    hci_hal->hci = &hci;

    if (hci_initialize()) {
        //wait for iniialization complete
        ALOGD("--%s waiting for iniialization complete hci state: %d ",
                __func__, hci.state);
        if(hci.state == FM_RADIO_ENABLING){
            Lock lk(hci.on_mtx);
            hci.on_cond.wait(lk);
        }
    }

    if (hci.state == FM_RADIO_ENABLED) {
        while (hci.is_tx_thread_running == false
            || hci.is_rx_thread_running == false)
        {
            /* checking tx & rx thread running status after every
               5ms before notifying on to upper layer */
            usleep(5000);
        }
        ALOGD("--%s success", __func__);
        ret = FM_HC_STATUS_SUCCESS;
    } else {
       ALOGD("--%s failed", __func__);
       hci_close();
       hci.state = FM_RADIO_DISABLED;
    }
    return ret;
}

/*******************************************************************************
**
** Function         fm_hci_transmit
**
** Description      This function is called by helium hal & is used enqueue the
**                  tx commands in tx queue.
**
** Parameters:      p_hci - contains the fm helium hal hci pointer
**                  hdr - contains the fm command header pointer
**
** Returns          void
**
*******************************************************************************/
int fm_hci_transmit(void *p_hci, struct fm_command_header_t *hdr)
{
    if (!hdr) {
        ALOGE("NULL input arguments");
        return FM_HC_STATUS_NULL_POINTER;
    }

    return enqueue_fm_tx_cmd(hdr);
}

/*******************************************************************************
**
** Function         fm_hci_close
**
** Description      This function is used to close & cleanup hci
**
** Parameters:      p_hci - contains the fm hci pointer
**
**
** Returns          void
**
*******************************************************************************/
void fm_hci_close(void *p_hci)
{
    ALOGI("%s", __func__);
    hci.state = FM_RADIO_DISABLING;

    hci_close();
    stop_tx_thread();

    if (hci.cb && hci.cb->fm_hci_close_done) {
        ALOGI("%s:Notify FM OFF to hal", __func__);
        hci.cb->fm_hci_close_done();
    }

    hci.state = FM_RADIO_DISABLED;
}