Home | History | Annotate | Download | only in avrc
      1 /******************************************************************************
      2  *
      3  *  Copyright 2003-2016 Broadcom Corporation
      4  *
      5  *  Licensed under the Apache License, Version 2.0 (the "License");
      6  *  you may not use this file except in compliance with the License.
      7  *  You may obtain a copy of the License at:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  VRCP internal header file.
     22  *
     23  ******************************************************************************/
     24 
     25 #ifndef AVRC_INT_H
     26 #define AVRC_INT_H
     27 
     28 #include "avct_defs.h"
     29 #include "avrc_api.h"
     30 #include "osi/include/alarm.h"
     31 #include "osi/include/fixed_queue.h"
     32 
     33 /*      DEBUG FLAGS
     34  *
     35  * #define META_DEBUG_ENABLED
     36  */
     37 /*****************************************************************************
     38  *  Constants
     39  ****************************************************************************/
     40 
     41 /* Number of attributes in AVRC SDP record. */
     42 #define AVRC_NUM_ATTR 6
     43 
     44 /* Number of protocol elements in protocol element list. */
     45 #define AVRC_NUM_PROTO_ELEMS 2
     46 
     47 #ifndef AVRC_MIN_CMD_LEN
     48 #define AVRC_MIN_CMD_LEN 20
     49 #endif
     50 
     51 #define AVRC_UNIT_OPRND_BYTES 5
     52 #define AVRC_SUB_OPRND_BYTES 4
     53 #define AVRC_SUBRSP_OPRND_BYTES 3
     54 #define AVRC_SUB_PAGE_MASK 7
     55 #define AVRC_SUB_PAGE_SHIFT 4
     56 #define AVRC_SUB_EXT_CODE 7
     57 #define AVRC_PASS_OP_ID_MASK 0x7F
     58 #define AVRC_PASS_STATE_MASK 0x80
     59 #define AVRC_CMD_OPRND_PAD 0xFF
     60 
     61 #define AVRC_CTYPE_MASK 0x0F
     62 #define AVRC_SUBTYPE_MASK 0xF8
     63 #define AVRC_SUBTYPE_SHIFT 3
     64 #define AVRC_SUBID_MASK 0x07
     65 #define AVRC_SUBID_IGNORE 0x07
     66 
     67 #define AVRC_SINGLE_PARAM_SIZE 1
     68 #define AVRC_METADATA_PKT_TYPE_MASK 0x03
     69 #define AVRC_PASS_THOUGH_MSG_MASK \
     70   0x80 /* MSB of msg_type indicates the PAS THROUGH msg */
     71 #define AVRC_VENDOR_UNIQUE_MASK 0x70 /* vendor unique id */
     72 
     73 /* Company ID is 24-bit integer We can not use the macros in bt_types.h */
     74 #define AVRC_CO_ID_TO_BE_STREAM(p, u32) \
     75   {                                     \
     76     *(p)++ = (uint8_t)((u32) >> 16);    \
     77     *(p)++ = (uint8_t)((u32) >> 8);     \
     78     *(p)++ = (uint8_t)(u32);            \
     79   }
     80 #define AVRC_BE_STREAM_TO_CO_ID(u32, p)                                   \
     81   {                                                                       \
     82     (u32) = (((uint32_t)(*((p) + 2))) + (((uint32_t)(*((p) + 1))) << 8) + \
     83              (((uint32_t)(*(p))) << 16));                                 \
     84     (p) += 3;                                                             \
     85   }
     86 
     87 #define AVRC_AVC_HDR_SIZE 3 /* ctype, subunit*, opcode */
     88 
     89 #define AVRC_MIN_META_HDR_SIZE 4   /* pdu id(1), packet type(1), param len(2) */
     90 #define AVRC_MIN_BROWSE_HDR_SIZE 3 /* pdu id(1), param len(2) */
     91 
     92 #define AVRC_VENDOR_HDR_SIZE 6 /* ctype, subunit*, opcode, CO_ID */
     93 #define AVRC_MSG_VENDOR_OFFSET 23
     94 #define AVRC_MIN_VENDOR_SIZE \
     95   (AVRC_MSG_VENDOR_OFFSET + BT_HDR_SIZE + AVRC_MIN_META_HDR_SIZE)
     96 
     97 #define AVRC_PASS_THRU_SIZE 8
     98 #define AVRC_MSG_PASS_THRU_OFFSET 25
     99 #define AVRC_MIN_PASS_THRU_SIZE (AVRC_MSG_PASS_THRU_OFFSET + BT_HDR_SIZE + 4)
    100 
    101 #define AVRC_MIN_BROWSE_SIZE \
    102   (AVCT_BROWSE_OFFSET + BT_HDR_SIZE + AVRC_MIN_BROWSE_HDR_SIZE)
    103 
    104 #define AVRC_CTRL_PKT_LEN(pf, pk) \
    105   { (pf) = (uint8_t*)((pk) + 1) + (pk)->offset + 2; }
    106 
    107 #define AVRC_MAX_CTRL_DATA_LEN (AVRC_PACKET_LEN)
    108 
    109 /* Timeout for waiting for avrc command responses (in milliseconds) */
    110 #ifndef AVRC_CMD_TOUT_MS
    111 #define AVRC_CMD_TOUT_MS (2 * 1000)
    112 #endif
    113 
    114 /* Flags for avrc_cb.ccb_int[].flags */
    115 #define AVRC_CB_FLAGS_RSP_PENDING 0x01 /* Waiting for AVRC response */
    116 
    117 /*****************************************************************************
    118  *  Type definitions
    119  ****************************************************************************/
    120 
    121 /* type for Metadata fragmentation control block */
    122 typedef struct {
    123   BT_HDR* p_fmsg;    /* the fragmented message */
    124   uint8_t frag_pdu;  /* the PDU ID for fragmentation */
    125   bool frag_enabled; /* fragmentation flag */
    126 } tAVRC_FRAG_CB;
    127 
    128 /* type for Metadata re-assembly control block */
    129 typedef struct {
    130   BT_HDR* p_rmsg;       /* the received message */
    131   uint16_t rasm_offset; /* re-assembly flag, the offset of the start fragment */
    132   uint8_t rasm_pdu;     /* the PDU ID for re-assembly */
    133 } tAVRC_RASM_CB;
    134 
    135 /* AVRC internal connection control block */
    136 typedef struct {
    137   fixed_queue_t*
    138       cmd_q;     /* Command queue for serializing vendor specific commands */
    139   uint8_t flags; /* See AVRC_CB_FLAGS_* definitions */
    140   alarm_t* tle;  /* Command timeout timer */
    141 } tAVRC_CONN_INT_CB;
    142 
    143 typedef struct {
    144   tAVRC_CONN_CB
    145       ccb[AVCT_NUM_CONN]; /* Connection control block from AVRC_Open API */
    146   tAVRC_CONN_INT_CB
    147       ccb_int[AVCT_NUM_CONN]; /* Internal connection control block  */
    148   tAVRC_FRAG_CB fcb[AVCT_NUM_CONN];
    149   tAVRC_RASM_CB rcb[AVCT_NUM_CONN];
    150   tAVRC_FIND_CBACK find_cback; /* sdp discovery callback */
    151   tSDP_DISCOVERY_DB* p_db;   /* pointer to discovery database */
    152   uint16_t service_uuid;     /* service UUID to search */
    153   uint8_t trace_level;
    154 } tAVRC_CB;
    155 
    156 /******************************************************************************
    157  * Main Control Block
    158  ******************************************************************************/
    159 extern tAVRC_CB avrc_cb;
    160 
    161 extern bool avrc_is_valid_pdu_id(uint8_t pdu_id);
    162 extern bool avrc_is_valid_player_attrib_value(uint8_t attrib, uint8_t value);
    163 extern BT_HDR* avrc_alloc_ctrl_pkt(uint8_t pdu);
    164 extern tAVRC_STS avrc_pars_pass_thru(tAVRC_MSG_PASS* p_msg,
    165                                      uint16_t* p_vendor_unique_id);
    166 extern uint8_t avrc_opcode_from_pdu(uint8_t pdu);
    167 extern bool avrc_is_valid_opcode(uint8_t opcode);
    168 extern void avrc_flush_cmd_q(uint8_t handle);
    169 void avrc_start_cmd_timer(uint8_t handle, uint8_t label, uint8_t msg_mask);
    170 void avrc_send_next_vendor_cmd(uint8_t handle);
    171 
    172 #endif /* AVRC_INT_H */
    173