static void csrhci_in_packet(struct csrhci_s *s, uint8_t *pkt)

{

    uint8_t *rpkt;

    int opc;



    switch (*pkt ++) {

    case H4_CMD_PKT:

        opc = le16_to_cpu(((struct hci_command_hdr *) pkt)->opcode);

        if (cmd_opcode_ogf(opc) == OGF_VENDOR_CMD) {

            csrhci_in_packet_vendor(s, cmd_opcode_ocf(opc),

                            pkt + sizeof(struct hci_command_hdr),

                            s->in_len - sizeof(struct hci_command_hdr) - 1);

            return;

        }



        /* TODO: if the command is OCF_READ_LOCAL_COMMANDS or the likes,

         * we need to send it to the HCI layer and then add our supported

         * commands to the returned mask (such as OGF_VENDOR_CMD).  With

         * bt-hci.c we could just have hooks for this kind of commands but

         * we can't with bt-host.c.  */



        s->hci->cmd_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_EVT_PKT:

        goto bad_pkt;



    case H4_ACL_PKT:

        s->hci->acl_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_SCO_PKT:

        s->hci->sco_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_NEG_PKT:

        if (s->in_hdr != sizeof(csrhci_neg_packet) ||

                        memcmp(pkt - 1, csrhci_neg_packet, s->in_hdr)) {

            fprintf(stderr, "%s: got a bad NEG packet\n", __func__);

            return;

        }

        pkt += 2;



        rpkt = csrhci_out_packet_csr(s, H4_NEG_PKT, 10);



        *rpkt ++ = 0x20;	/* Operational settings negotiation Ok */

        memcpy(rpkt, pkt, 7); rpkt += 7;

        *rpkt ++ = 0xff;

        *rpkt = 0xff;

        break;



    case H4_ALIVE_PKT:

        if (s->in_hdr != 4 || pkt[1] != 0x55 || pkt[2] != 0x00) {

            fprintf(stderr, "%s: got a bad ALIVE packet\n", __func__);

            return;

        }



        rpkt = csrhci_out_packet_csr(s, H4_ALIVE_PKT, 2);



        *rpkt ++ = 0xcc;

        *rpkt = 0x00;

        break;



    default:

    bad_pkt:

        /* TODO: error out */

        fprintf(stderr, "%s: got a bad packet\n", __func__);

        break;

    }



    csrhci_fifo_wake(s);

}

static void csrhci_in_packet(struct csrhci_s *s, uint8_t *pkt)

{

    uint8_t *rpkt;

    int opc;



    switch (*pkt ++) {

    case H4_CMD_PKT:

        opc = le16_to_cpu(((struct hci_command_hdr *) pkt)->opcode);

        if (cmd_opcode_ogf(opc) == OGF_VENDOR_CMD) {

            csrhci_in_packet_vendor(s, cmd_opcode_ocf(opc),

                            pkt + sizeof(struct hci_command_hdr),

                            s->in_len - sizeof(struct hci_command_hdr) - 1);

            return;

        }



        











        s->hci->cmd_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_EVT_PKT:

        goto bad_pkt;



    case H4_ACL_PKT:

        s->hci->acl_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_SCO_PKT:

        s->hci->sco_send(s->hci, pkt, s->in_len - 1);

        break;



    case H4_NEG_PKT:

        if (s->in_hdr != sizeof(csrhci_neg_packet) ||

                        memcmp(pkt - 1, csrhci_neg_packet, s->in_hdr)) {

            fprintf(stderr, "%s: got a bad NEG packet\n", __func__);

            return;

        }

        pkt += 2;



        rpkt = csrhci_out_packet_csr(s, H4_NEG_PKT, 10);



        *rpkt ++ = 0x20;	

        memcpy(rpkt, pkt, 7); rpkt += 7;

        *rpkt ++ = 0xff;

        *rpkt = 0xff;

        break;



    case H4_ALIVE_PKT:

        if (s->in_hdr != 4 || pkt[1] != 0x55 || pkt[2] != 0x00) {

            fprintf(stderr, "%s: got a bad ALIVE packet\n", __func__);

            return;

        }



        rpkt = csrhci_out_packet_csr(s, H4_ALIVE_PKT, 2);



        *rpkt ++ = 0xcc;

        *rpkt = 0x00;

        break;



    default:

    bad_pkt:

        

        fprintf(stderr, "%s: got a bad packet\n", __func__);

        break;

    }



    csrhci_fifo_wake(s);

}

static void FUNC_0(struct csrhci_s *VAR_0, uint8_t *VAR_1)

{

    uint8_t *rpkt;

    int VAR_2;



    switch (*VAR_1 ++) {

    case H4_CMD_PKT:

        VAR_2 = le16_to_cpu(((struct hci_command_hdr *) VAR_1)->opcode);

        if (cmd_opcode_ogf(VAR_2) == OGF_VENDOR_CMD) {

            csrhci_in_packet_vendor(VAR_0, cmd_opcode_ocf(VAR_2),

                            VAR_1 + sizeof(struct hci_command_hdr),

                            VAR_0->in_len - sizeof(struct hci_command_hdr) - 1);

            return;

        }



        











        VAR_0->hci->cmd_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1);

        break;



    case H4_EVT_PKT:

        goto bad_pkt;



    case H4_ACL_PKT:

        VAR_0->hci->acl_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1);

        break;



    case H4_SCO_PKT:

        VAR_0->hci->sco_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1);

        break;



    case H4_NEG_PKT:

        if (VAR_0->in_hdr != sizeof(csrhci_neg_packet) ||

                        memcmp(VAR_1 - 1, csrhci_neg_packet, VAR_0->in_hdr)) {

            fprintf(stderr, "%VAR_0: got a bad NEG packet\n", __func__);

            return;

        }

        VAR_1 += 2;



        rpkt = csrhci_out_packet_csr(VAR_0, H4_NEG_PKT, 10);



        *rpkt ++ = 0x20;	

        memcpy(rpkt, VAR_1, 7); rpkt += 7;

        *rpkt ++ = 0xff;

        *rpkt = 0xff;

        break;



    case H4_ALIVE_PKT:

        if (VAR_0->in_hdr != 4 || VAR_1[1] != 0x55 || VAR_1[2] != 0x00) {

            fprintf(stderr, "%VAR_0: got a bad ALIVE packet\n", __func__);

            return;

        }



        rpkt = csrhci_out_packet_csr(VAR_0, H4_ALIVE_PKT, 2);



        *rpkt ++ = 0xcc;

        *rpkt = 0x00;

        break;



    default:

    bad_pkt:

        

        fprintf(stderr, "%VAR_0: got a bad packet\n", __func__);

        break;

    }



    csrhci_fifo_wake(VAR_0);

}

static void FUNC_0(struct csrhci_s *VAR_0, uint8_t *VAR_1)
{ uint8_t *rpkt; int VAR_2; switch (*VAR_1 ++) { case H4_CMD_PKT:
VAR_2 = le16_to_cpu(((struct hci_command_hdr *) VAR_1)->opcode); if (cmd_opcode_ogf(VAR_2) == OGF_VENDOR_CMD) { csrhci_in_packet_vendor(VAR_0, cmd_opcode_ocf(VAR_2),
VAR_1 + sizeof(struct hci_command_hdr),
VAR_0->in_len - sizeof(struct hci_command_hdr) - 1); return; } VAR_0->hci->cmd_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1); break; case H4_EVT_PKT:
goto bad_pkt; case H4_ACL_PKT:
VAR_0->hci->acl_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1); break; case H4_SCO_PKT:
VAR_0->hci->sco_send(VAR_0->hci, VAR_1, VAR_0->in_len - 1); break; case H4_NEG_PKT:
if (VAR_0->in_hdr != sizeof(csrhci_neg_packet) ||
memcmp(VAR_1 - 1, csrhci_neg_packet, VAR_0->in_hdr)) { fprintf(stderr, "%VAR_0: got a bad NEG packet\n", __func__); return; } VAR_1 += 2; rpkt = csrhci_out_packet_csr(VAR_0, H4_NEG_PKT, 10); *rpkt ++ = 0x20; memcpy(rpkt, VAR_1, 7); rpkt += 7; *rpkt ++ = 0xff; *rpkt = 0xff; break; case H4_ALIVE_PKT:
if (VAR_0->in_hdr != 4 || VAR_1[1] != 0x55 || VAR_1[2] != 0x00) { fprintf(stderr, "%VAR_0: got a bad ALIVE packet\n", __func__); return; } rpkt = csrhci_out_packet_csr(VAR_0, H4_ALIVE_PKT, 2); *rpkt ++ = 0xcc; *rpkt = 0x00; break; default:
bad_pkt:
fprintf(stderr, "%VAR_0: got a bad packet\n", __func__); break; } csrhci_fifo_wake(VAR_0); }