Lines Matching full:h5

273 static uint16_t h5_get_crc(struct rtb_struct * h5)  in h5_get_crc()  argument
276 uint8_t *data = h5->rx_skb->data + h5->rx_skb->data_len - 2; in h5_get_crc()
280 /* return get_unaligned_be16(&h5->rx_skb->data[h5->rx_skb->data_len - 2]); */ in h5_get_crc()
293 * Encode one byte in h5 proto
331 * Decode one byte in h5 proto
338 static void h5_unslip_one_byte(struct rtb_struct * h5, unsigned char byte) in h5_unslip_one_byte() argument
343 if (H5_ESCSTATE_NOESC == h5->rx_esc_state) { in h5_unslip_one_byte()
345 h5->rx_esc_state = H5_ESCSTATE_ESC; in h5_unslip_one_byte()
347 memcpy(skb_put(h5->rx_skb, 1), &byte, 1); in h5_unslip_one_byte()
349 if ((h5->rx_skb->data[0] & 0x40) != 0 && in h5_unslip_one_byte()
350 h5->rx_state != H5_W4_CRC) { in h5_unslip_one_byte()
351 h5_crc_update(&h5->message_crc, byte); in h5_unslip_one_byte()
353 h5->rx_count--; in h5_unslip_one_byte()
355 } else if (H5_ESCSTATE_ESC == h5->rx_esc_state) { in h5_unslip_one_byte()
358 memcpy(skb_put(h5->rx_skb, 1), &c0, 1); in h5_unslip_one_byte()
359 if ((h5->rx_skb->data[0] & 0x40) != 0 && in h5_unslip_one_byte()
360 h5->rx_state != H5_W4_CRC) in h5_unslip_one_byte()
361 h5_crc_update(&h5->message_crc, 0xc0); in h5_unslip_one_byte()
362 h5->rx_esc_state = H5_ESCSTATE_NOESC; in h5_unslip_one_byte()
363 h5->rx_count--; in h5_unslip_one_byte()
367 memcpy(skb_put(h5->rx_skb, 1), &db, 1); in h5_unslip_one_byte()
368 if ((h5->rx_skb->data[0] & 0x40) != 0 && in h5_unslip_one_byte()
369 h5->rx_state != H5_W4_CRC) in h5_unslip_one_byte()
370 h5_crc_update(&h5->message_crc, 0xdb); in h5_unslip_one_byte()
371 h5->rx_esc_state = H5_ESCSTATE_NOESC; in h5_unslip_one_byte()
372 h5->rx_count--; in h5_unslip_one_byte()
376 memcpy(skb_put(h5->rx_skb, 1), &oof1, 1); in h5_unslip_one_byte()
377 if ((h5->rx_skb->data[0] & 0x40) != 0 && in h5_unslip_one_byte()
378 h5->rx_state != H5_W4_CRC) in h5_unslip_one_byte()
379 h5_crc_update(&h5->message_crc, oof1); in h5_unslip_one_byte()
380 h5->rx_esc_state = H5_ESCSTATE_NOESC; in h5_unslip_one_byte()
381 h5->rx_count--; in h5_unslip_one_byte()
385 memcpy(skb_put(h5->rx_skb, 1), &oof2, 1); in h5_unslip_one_byte()
386 if ((h5->rx_skb->data[0] & 0x40) != 0 && in h5_unslip_one_byte()
387 h5->rx_state != H5_W4_CRC) in h5_unslip_one_byte()
388 h5_crc_update(&h5->message_crc, oof2); in h5_unslip_one_byte()
389 h5->rx_esc_state = H5_ESCSTATE_NOESC; in h5_unslip_one_byte()
390 h5->rx_count--; in h5_unslip_one_byte()
395 skb_free(h5->rx_skb); in h5_unslip_one_byte()
396 h5->rx_skb = NULL; in h5_unslip_one_byte()
397 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_unslip_one_byte()
398 h5->rx_count = 0; in h5_unslip_one_byte()
405 * Prepare h5 packet
409 static struct sk_buff *h5_prepare_pkt(struct rtb_struct * h5, uint8_t *data, in h5_prepare_pkt() argument
435 /* Max len of packet: (len + 4(h5 hdr) + 2(crc))*2 in h5_prepare_pkt()
448 hdr[0] = h5->rxseq_txack << 3; in h5_prepare_pkt()
449 h5->is_txack_req = 0; in h5_prepare_pkt()
451 /* RS_DBG("Request packet no(%u) to card", h5->rxseq_txack); */ in h5_prepare_pkt()
452 /* RS_DBG("Sending packet with seqno %u and wait %u", h5->msgq_txseq, in h5_prepare_pkt()
453 * h5->rxseq_txack); in h5_prepare_pkt()
457 hdr[0] |= 0x80 + h5->msgq_txseq; in h5_prepare_pkt()
458 /* RS_DBG("Sending packet with seqno(%u)", h5->msgq_txseq); */ in h5_prepare_pkt()
459 ++(h5->msgq_txseq); in h5_prepare_pkt()
460 h5->msgq_txseq = (h5->msgq_txseq) & 0x07; in h5_prepare_pkt()
463 if (h5->use_crc) in h5_prepare_pkt()
472 /* Encode h5 header */ in h5_prepare_pkt()
476 if (h5->use_crc) in h5_prepare_pkt()
484 if (h5->use_crc) in h5_prepare_pkt()
489 if (h5->use_crc) { in h5_prepare_pkt()
503 /* static void h5_remove_acked_pkt(struct rtb_struct * h5)
509 * seqno = h5->msgq_txseq;
510 * // pkts_to_be_removed = GetListLength(h5->unacked);
513 * if (h5->rxack == seqno)
520 * if (h5->rxack != seqno) {
523 * // skb_queue_walk_safe(&h5->unack, skb, tmp)
524 * // remove ack'ed packet from h5->unack queue
529 * //__skb_unlink(skb, &h5->unack);
533 * // if (skb_queue_empty(&h5->unack))
534 * // del_timer(&h5->th5);
535 * // spin_unlock_irqrestore(&h5->unack.lock, flags);
560 * Parse hci command complete event in h5 init state.
630 * Parse hci command complete event in h5 post state.
727 RS_ERR("Send h5 sync resp error, %s", in h5_handle_internal_rx()
738 RS_ERR("Send h5 sync resp error, %s", in h5_handle_internal_rx()
744 RS_ERR("Send h5 sync resp to ctl error, %s", in h5_handle_internal_rx()
764 * Process the received complete h5 packet
766 static void h5_complete_rx_pkt(struct rtb_struct *h5) in h5_complete_rx_pkt() argument
771 h5_hdr = (uint8_t *) (h5->rx_skb->data); in h5_complete_rx_pkt()
773 /* RS_DBG("Received reliable seqno %u from card", h5->rxseq_txack); in h5_complete_rx_pkt()
775 h5->rxseq_txack = H5_HDR_SEQ(h5_hdr) + 1; in h5_complete_rx_pkt()
776 /* h5->rxseq_txack %= 8; */ in h5_complete_rx_pkt()
777 h5->rxseq_txack &= 0x07; in h5_complete_rx_pkt()
778 h5->is_txack_req = 1; in h5_complete_rx_pkt()
781 h5->rxack = H5_HDR_ACK(h5_hdr); in h5_complete_rx_pkt()
787 /* h5_remove_acked_pkt(h5); */ in h5_complete_rx_pkt()
795 skb_pull(h5->rx_skb, H5_HDR_SIZE); in h5_complete_rx_pkt()
796 h5_handle_internal_rx(h5->rx_skb); in h5_complete_rx_pkt()
804 skb_pull(h5->rx_skb, H5_HDR_SIZE); in h5_complete_rx_pkt()
805 hci_recv_frame(h5->rx_skb); in h5_complete_rx_pkt()
808 if (h5->is_txack_req) { in h5_complete_rx_pkt()
810 h5->is_txack_req = 0; in h5_complete_rx_pkt()
813 skb_free(h5->rx_skb); in h5_complete_rx_pkt()
815 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_complete_rx_pkt()
816 h5->rx_skb = NULL; in h5_complete_rx_pkt()
820 * Parse the receive data in h5 proto.
822 static int h5_recv(struct rtb_struct *h5, void *data, int count) in h5_recv() argument
828 if (h5->rx_count) { in h5_recv()
830 RS_ERR("Short h5 packet"); in h5_recv()
831 skb_free(h5->rx_skb); in h5_recv()
832 h5->rx_state = H5_W4_PKT_START; in h5_recv()
833 h5->rx_count = 0; in h5_recv()
835 h5_unslip_one_byte(h5, *ptr); in h5_recv()
842 switch (h5->rx_state) { in h5_recv()
845 if ((0xff & (uint8_t)~(h5->rx_skb->data[0] + h5->rx_skb->data[1] + in h5_recv()
846 h5->rx_skb->data[2])) != h5->rx_skb->data[3]) { in h5_recv()
847 RS_ERR("h5 hdr checksum error"); in h5_recv()
848 skb_free(h5->rx_skb); in h5_recv()
849 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_recv()
850 h5->rx_count = 0; in h5_recv()
855 if (h5->rx_skb->data[0] & 0x80 && in h5_recv()
856 (h5->rx_skb->data[0] & 0x07) != h5->rxseq_txack) { in h5_recv()
857 uint8_t rxseq_txack = (h5->rx_skb->data[0] & 0x07); in h5_recv()
859 h5->rx_skb->data[0] & 0x07, in h5_recv()
860 h5->rxseq_txack); in h5_recv()
861 h5->is_txack_req = 1; in h5_recv()
863 skb_free(h5->rx_skb); in h5_recv()
864 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_recv()
865 h5->rx_count = 0; in h5_recv()
876 h5->rx_state = H5_W4_DATA; in h5_recv()
877 h5->rx_count = in h5_recv()
878 (h5->rx_skb->data[1] >> 4) + in h5_recv()
879 (h5->rx_skb->data[2] << 4); in h5_recv()
884 if (h5->rx_skb->data[0] & 0x40) { in h5_recv()
885 h5->rx_state = H5_W4_CRC; in h5_recv()
886 h5->rx_count = 2; in h5_recv()
888 h5_complete_rx_pkt(h5); in h5_recv()
893 if (bit_rev16(h5->message_crc) != h5_get_crc(h5)) { in h5_recv()
895 bit_rev16(h5->message_crc), in h5_recv()
896 h5_get_crc(h5)); in h5_recv()
897 skb_free(h5->rx_skb); in h5_recv()
898 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_recv()
899 h5->rx_count = 0; in h5_recv()
902 skb_trim(h5->rx_skb, h5->rx_skb->data_len - 2); in h5_recv()
903 h5_complete_rx_pkt(h5); in h5_recv()
909 h5->rx_state = H5_W4_PKT_START; in h5_recv()
927 h5->rx_state = H5_W4_HDR; in h5_recv()
928 h5->rx_count = 4; in h5_recv()
929 h5->rx_esc_state = H5_ESCSTATE_NOESC; in h5_recv()
930 H5_CRC_INIT(h5->message_crc); in h5_recv()
933 * Allocate packet. Max len of a H5 pkt= in h5_recv()
936 h5->rx_skb = skb_alloc(0x1005); in h5_recv()
937 if (!h5->rx_skb) { in h5_recv()
939 h5->rx_state = H5_W4_PKT_DELIMITER; in h5_recv()
940 h5->rx_count = 0; in h5_recv()
1093 /* h5 sync or config */ in start_transmit_wait()
1331 * Init realtek Bluetooth h5 proto.
1332 * There are two steps: h5 sync and h5 config.
1353 /* h5 sync */ in rtb_init_h5()
1364 /* h5 config */ in rtb_init_h5()
1374 RS_DBG("H5 init finished\n"); in rtb_init_h5()
1743 RS_INFO("Realtek H5 IC"); in rtb_config()