AVRCP: use a vtable to simplify PDU parsing/handling
Subsystems (2)
Luiz Augusto von Dentz
maintainerPATCH 1/5 AVRCP: use a vtable to simplify PDU parsing/handling
From: Luiz Augusto von Dentz <[email protected]>
This simplify a bit the handling by introducing common checks before calling the handler callback, it is also much easier to add/remove new PDUs in this way.
--- audio/control.c | 321 +++++++++++++++++++++---------------------------------- 1 files changed, 124 insertions(+), 197 deletions(-)
audio/control.c +124 -197
@@ -986,8 +986,9 @@ static void mp_set_media_attributes(struct control *control,avctp_send_event (control,AVRCP_EVENT_TRACK_CHANGED ,NULL ); } -static int avrcp_handle_get_capabilities (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_capabilities (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);unsigned int i;
@@ -1008,31 +1009,35 @@ static int avrcp_handle_get_capabilities(struct control *control, pdu->params_len =htons (2 + (3 *G_N_ELEMENTS (company_ids))); pdu->params[1 ] =G_N_ELEMENTS (company_ids); -return 2 + (3 *G_N_ELEMENTS (company_ids)); +return CTYPE_STABLE ;case CAP_EVENTS_SUPPORTED : pdu->params_len =htons (4 ); pdu->params[1 ] =2 ; pdu->params[2 ] =AVRCP_EVENT_PLAYBACK_STATUS_CHANGED ; pdu->params[3 ] =AVRCP_EVENT_TRACK_CHANGED ; -return 4 ; +return CTYPE_STABLE ; } err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; + +return CTYPE_REJECTED ; } -static int avrcp_handle_list_player_attributes (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_list_player_attributes (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);struct media_player *mp = control->mp;unsigned int i;if (len !=0 ) { + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; }if (!mp)
@@ -1052,11 +1057,12 @@ done: pdu->params[0 ] = len; pdu->params_len =htons (len +1 ); -return len +1 ; +return CTYPE_STABLE ; } -static int avrcp_handle_list_player_values (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_list_player_values (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);struct media_player *mp = control->mp;
@@ -1077,15 +1083,17 @@ static int avrcp_handle_list_player_values(struct control *control, pdu->params[0 ] = len; pdu->params_len =htons (len +1 ); -return len +1 ; +return CTYPE_STABLE ; err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } -static int avrcp_handle_get_element_attributes (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_element_attributes (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);uint64_t *identifier = (void *) &pdu->params[0 ];
@@ -1145,14 +1153,16 @@ done: pdu->params[0 ] = len; pdu->params_len =htons (pos); -return pos; +return CTYPE_STABLE ; err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } -static int avrcp_handle_get_current_player_value (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_current_player_value (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);struct media_player *mp = control->mp;
@@ -1202,19 +1212,21 @@ static int avrcp_handle_get_current_player_value(struct control *control, pdu->params[0 ] = len; pdu->params_len =htons (2 * len +1 ); -return 2 * len +1 ; +return CTYPE_STABLE ; }error ("No valid attributes in request" ); err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } -static int avrcp_handle_set_player_value (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_set_player_value (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);unsigned int i;
@@ -1256,16 +1268,38 @@ static int avrcp_handle_set_player_value(struct control *control,if (len) { pdu->params_len =0 ; -return 0 ; +return CTYPE_STABLE ; } err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } -static int avrcp_handle_ct_battery_status (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_displayable_charset (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) +{ +uint16_t len =ntohs (pdu->params_len); + +if (len <3 ) { + pdu->params_len =htons (1 ); + pdu->params[0 ] =E_INVALID_PARAM ; +return CTYPE_REJECTED ; + } + +/* +* We acknowledge the commands, but we always use UTF-8 for +* encoding since CT is obliged to support it. +*/ + pdu->params_len =0 ; +return CTYPE_STABLE ; +} + +static uint8_t avrcp_handle_ct_battery_status (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);const char *valstr;
@@ -1282,15 +1316,17 @@ static int avrcp_handle_ct_battery_status(struct control *control, DBUS_TYPE_STRING, &valstr); pdu->params_len =0 ; -return 0 ; +return CTYPE_STABLE ; err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } -static int avrcp_handle_get_play_status (struct control *control, -struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_play_status (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);uint32_t elapsed;
@@ -1298,8 +1334,9 @@ static int avrcp_handle_get_play_status(struct control *control,uint8_t status;if (len !=0 ) { + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; }if (control->mp) {
@@ -1319,10 +1356,10 @@ static int avrcp_handle_get_play_status(struct control *control, pdu->params_len =htons (9 ); -return 9 ; +return CTYPE_STABLE ; } -static int avrcp_handle_register_notification (struct control *control, +static uint8_t avrcp_handle_register_notification (struct control *control,struct avrcp_spec_avc_pdu *pdu,uint8_t transaction) {
@@ -1369,24 +1406,59 @@ static int avrcp_handle_register_notification(struct control *control, pdu->params_len =htons (len); -return len; +return CTYPE_INTERIM ; err: + pdu->params_len =htons (1 ); pdu->params[0 ] =E_INVALID_PARAM ; -return -EINVAL ; +return CTYPE_REJECTED ; } +static struct pdu_handler { +uint8_t pdu_id; +uint8_t code; +uint8_t (*func) (struct control *control, +struct avrcp_spec_avc_pdu *pdu, +uint8_t transaction); +} handlers[] = { + {AVRCP_GET_CAPABILITIES ,CTYPE_STATUS , + avrcp_handle_get_capabilities }, + {AVRCP_LIST_PLAYER_ATTRIBUTES ,CTYPE_STATUS , + avrcp_handle_list_player_attributes }, + {AVRCP_LIST_PLAYER_VALUES ,CTYPE_STATUS , + avrcp_handle_list_player_values }, + {AVRCP_GET_ELEMENT_ATTRIBUTES ,CTYPE_STATUS , + avrcp_handle_get_element_attributes }, + {AVRCP_GET_CURRENT_PLAYER_VALUE ,CTYPE_STATUS , + avrcp_handle_get_current_player_value }, + {AVRCP_SET_PLAYER_VALUE ,CTYPE_CONTROL , + avrcp_handle_set_player_value }, + {AVRCP_GET_PLAYER_ATTRIBUTE_TEXT ,CTYPE_STATUS , +NULL }, + {AVRCP_GET_PLAYER_VALUE_TEXT ,CTYPE_STATUS , +NULL }, + {AVRCP_DISPLAYABLE_CHARSET ,CTYPE_STATUS , + avrcp_handle_displayable_charset }, + {AVRCP_CT_BATTERY_STATUS ,CTYPE_STATUS , + avrcp_handle_ct_battery_status }, + {AVRCP_GET_PLAY_STATUS ,CTYPE_STATUS , + avrcp_handle_get_play_status }, + {AVRCP_REGISTER_NOTIFICATION ,CTYPE_NOTIFY , + avrcp_handle_register_notification }, + { }, +}; +/* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu (struct control *control,struct avctp_header *avctp,struct avrcp_header *avrcp,int operand_count) { +struct pdu_handler *handler;struct avrcp_spec_avc_pdu *pdu = (void *) avrcp +AVRCP_HEADER_LENGTH ;uint32_t company_id = (pdu->company_id[0 ] <<16 ) | (pdu->company_id[1 ] <<8 ) | (pdu->company_id[2 ]); -int len;if (company_id !=IEEEID_BTSIG || pdu->packet_type !=AVCTP_PACKET_SINGLE ) {
@@ -1397,177 +1469,32 @@ static int handle_vendordep_pdu(struct control *control, pdu->packet_type =0 ; pdu->rsvd =0 ; -if (operand_count +3 <AVRCP_SPECAVCPDU_HEADER_LENGTH ) { - pdu->params[0 ] =E_INVALID_COMMAND ; +if (operand_count +3 <AVRCP_SPECAVCPDU_HEADER_LENGTH ) goto err_metadata; - } - -switch (pdu->pdu_id) { -case AVRCP_GET_CAPABILITIES : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_get_capabilities (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_LIST_PLAYER_ATTRIBUTES : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - len =avrcp_handle_list_player_attributes (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_LIST_PLAYER_VALUES : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_list_player_values (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_GET_ELEMENT_ATTRIBUTES : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_get_element_attributes (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_GET_CURRENT_PLAYER_VALUE : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_get_current_player_value (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_SET_PLAYER_VALUE : -if (avrcp->code !=CTYPE_CONTROL ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_set_player_value (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_GET_PLAYER_ATTRIBUTE_TEXT : -case AVRCP_GET_PLAYER_VALUE_TEXT : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } +for (handler = handlers; handler; handler++) { +if (handler->pdu_id == pdu->pdu_id) +break ; + } -/* -* As per sec. 5.2.5 of AVRCP 1.3 spec, this command is -* expected to be used only for extended attributes, i.e. -* custom attributes defined by the application. As we -* currently don't have any such attribute, we respond with -* invalid param id. -*/ - pdu->params[0 ] =E_INVALID_PARAM ; +if (!handler || handler->code != avrcp->code) { + pdu->params[0 ] =E_INVALID_COMMAND ; goto err_metadata; -case AVRCP_DISPLAYABLE_CHARSET : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - -if (pdu->params[0 ] <3 ) { - pdu->params[0 ] =E_INVALID_PARAM ; - goto err_metadata; - } - -/* -* We acknowledge the commands, but we always use UTF-8 for -* encoding since CT is obliged to support it. -*/ - pdu->params_len =0 ; - avrcp->code =CTYPE_STABLE ; - len =0 ; - -break ; -case AVRCP_CT_BATTERY_STATUS : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_ct_battery_status (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_GET_PLAY_STATUS : -if (avrcp->code !=CTYPE_STATUS ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_get_play_status (control, pdu); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_STABLE ; - -break ; -case AVRCP_REGISTER_NOTIFICATION : -if (avrcp->code !=CTYPE_NOTIFY ) { - pdu->params[0 ] =E_INVALID_COMMAND ; - goto err_metadata; - } - - len =avrcp_handle_register_notification (control, pdu, - avctp->transaction); -if (len <0 ) - goto err_metadata; - - avrcp->code =CTYPE_INTERIM ; + } -break ; -default : -/* Invalid pdu_id */ - pdu->params[0 ] =E_INVALID_COMMAND ; +if (!handler->func) { + pdu->params[0 ] =E_INVALID_PARAM ; goto err_metadata; } -return AVRCP_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH + len; + avrcp->code = handler->func (control, pdu, avctp->transaction); + +return AVRCP_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH + +ntohs (pdu->params_len); err_metadata: - avrcp->code =CTYPE_REJECTED ; pdu->params_len =htons (1 ); + avrcp->code =CTYPE_REJECTED ;return AVRCP_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +1 ; }
Signature · 1 line
1.7.6.1
Luiz Augusto von Dentz
maintainerPATCH 2/5 AVRCP: rename avrcp_header to avc_header
From: Luiz Augusto von Dentz <[email protected]>
AVCTP carries AV/C packets/PDUs not AVRCP as avrcp_header suggests.
--- audio/control.c | 98 +++++++++++++++++++++++++++--------------------------- 1 files changed, 49 insertions(+), 49 deletions(-)
audio/control.c +49 -49
@@ -212,14 +212,14 @@ struct avctp_header { } __attribute__ ((packed));#define AVCTP_HEADER_LENGTH 3 -struct avrcp_header { +struct avc_header {uint8_t code:4 ;uint8_t _hdr0:4 ;uint8_t subunit_id:3 ;uint8_t subunit_type:5 ;uint8_t opcode; } __attribute__ ((packed)); -#define AVRCP_HEADER_LENGTH 3 +#define AVC_HEADER_LENGTH 3struct avrcp_spec_avc_pdu {uint8_t company_id[3 ];
@@ -242,14 +242,14 @@ struct avctp_header { } __attribute__ ((packed));#define AVCTP_HEADER_LENGTH 3 -struct avrcp_header { +struct avc_header {uint8_t _hdr0:4 ;uint8_t code:4 ;uint8_t subunit_type:5 ;uint8_t subunit_id:3 ;uint8_t opcode; } __attribute__ ((packed)); -#define AVRCP_HEADER_LENGTH 3 +#define AVC_HEADER_LENGTH 3struct avrcp_spec_avc_pdu {uint8_t company_id[3 ];
@@ -721,13 +721,13 @@ static const char *battery_status_to_str(enum battery_status status)static int avctp_send_event (struct control *control,uint8_t id,void *data) { -uint8_t buf[AVCTP_HEADER_LENGTH +AVRCP_HEADER_LENGTH + +uint8_t buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +9 ];struct avctp_header *avctp = (void *) buf; -struct avrcp_header *avrcp = (void *) &buf[AVCTP_HEADER_LENGTH ]; +struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH ];struct avrcp_spec_avc_pdu *pdu = (void *) &buf[AVCTP_HEADER_LENGTH + -AVRCP_HEADER_LENGTH ]; -int sk; +AVC_HEADER_LENGTH ]; +int sk =g_io_channel_unix_get_fd (control->io);uint16_t size;if (control->state !=AVCTP_STATE_CONNECTED )
@@ -743,9 +743,9 @@ static int avctp_send_event(struct control *control, uint8_t id, void *data) avctp->cr =AVCTP_RESPONSE ; avctp->pid =htons (AV_REMOTE_SVCLASS_ID ); - avrcp->code =CTYPE_CHANGED ; - avrcp->subunit_type =SUBUNIT_PANEL ; - avrcp->opcode =OP_VENDORDEP ; + avc->code =CTYPE_CHANGED ; + avc->subunit_type =SUBUNIT_PANEL ; + avc->opcode =OP_VENDORDEP ; pdu->company_id[0 ] =IEEEID_BTSIG >>16 ; pdu->company_id[1 ] = (IEEEID_BTSIG >>8 ) &0xFF ;
@@ -780,7 +780,7 @@ static int avctp_send_event(struct control *control, uint8_t id, void *data) } pdu->params_len =htons (size); - size +=AVCTP_HEADER_LENGTH +AVRCP_HEADER_LENGTH + + size +=AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH ; sk =g_io_channel_unix_get_fd (control->io);
@@ -1451,19 +1451,19 @@ static struct pdu_handler {/* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu (struct control *control,struct avctp_header *avctp, -struct avrcp_header *avrcp, +struct avc_header *avc,int operand_count) {struct pdu_handler *handler; -struct avrcp_spec_avc_pdu *pdu = (void *) avrcp +AVRCP_HEADER_LENGTH ; +struct avrcp_spec_avc_pdu *pdu = (void *) avc +AVC_HEADER_LENGTH ;uint32_t company_id = (pdu->company_id[0 ] <<16 ) | (pdu->company_id[1 ] <<8 ) | (pdu->company_id[2 ]);if (company_id !=IEEEID_BTSIG || pdu->packet_type !=AVCTP_PACKET_SINGLE ) { - avrcp->code =CTYPE_NOT_IMPLEMENTED ; -return AVRCP_HEADER_LENGTH ; + avc->code =CTYPE_NOT_IMPLEMENTED ; +return AVC_HEADER_LENGTH ; } pdu->packet_type =0 ;
@@ -1477,7 +1477,7 @@ static int handle_vendordep_pdu(struct control *control,break ; } -if (!handler || handler->code != avrcp->code) { +if (!handler || handler->code != avc->code) { pdu->params[0 ] =E_INVALID_COMMAND ; goto err_metadata; }
@@ -1487,16 +1487,16 @@ static int handle_vendordep_pdu(struct control *control, goto err_metadata; } - avrcp->code = handler->func (control, pdu, avctp->transaction); + avc->code = handler->func (control, pdu, avctp->transaction); -return AVRCP_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH + +return AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +ntohs (pdu->params_len); err_metadata: pdu->params_len =htons (1 ); - avrcp->code =CTYPE_REJECTED ; + avc->code =CTYPE_REJECTED ; -return AVRCP_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +1 ; +return AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +1 ; }static void avctp_disconnected (struct audio_device *dev)
@@ -1593,7 +1593,7 @@ static gboolean control_cb(GIOChannel *chan, GIOCondition cond,struct control *control = data;unsigned char buf[1024 ], *operands;struct avctp_header *avctp; -struct avrcp_header *avrcp; +struct avc_header *avc;int ret, packet_size, operand_count, sock;if (cond & (G_IO_ERR |G_IO_HUP |G_IO_NVAL ))
@@ -1622,65 +1622,65 @@ static gboolean control_cb(GIOChannel *chan, GIOCondition cond, avctp->cr, avctp->ipid, ntohs(avctp->pid)); ret -=sizeof (struct avctp_header ); -if ((unsigned int ) ret <sizeof (struct avrcp_header )) { +if ((unsigned int ) ret <sizeof (struct avc_header )) {error ("Too small AVRCP packet" ); goto failed; } - avrcp = (struct avrcp_header *) (buf +sizeof (struct avctp_header )); + avc = (struct avc_header *) (buf +sizeof (struct avctp_header )); - ret -=sizeof (struct avrcp_header ); + ret -=sizeof (struct avc_header ); - operands = buf +sizeof (struct avctp_header ) +sizeof (struct avrcp_header ); + operands = buf +sizeof (struct avctp_header ) +sizeof (struct avc_header ); operand_count = ret; -DBG ("AVRCP %s 0x%01X, subunit_type 0x%02X, subunit_id 0x%01X, " +DBG ("AV/C %s 0x%01X, subunit_type 0x%02X, subunit_id 0x%01X, " "opcode 0x%02X, %d operands" , avctp->cr ?"response" :"command" , - avrcp->code, avrcp->subunit_type, avrcp->subunit_id, - avrcp->opcode, operand_count); + avc->code, avc->subunit_type, avc->subunit_id, + avc->opcode, operand_count);if (avctp->packet_type !=AVCTP_PACKET_SINGLE ) { avctp->cr =AVCTP_RESPONSE ; - avrcp->code =CTYPE_NOT_IMPLEMENTED ; + avc->code =CTYPE_NOT_IMPLEMENTED ; }else if (avctp->pid !=htons (AV_REMOTE_SVCLASS_ID )) { avctp->ipid =1 ; avctp->cr =AVCTP_RESPONSE ; packet_size =sizeof (*avctp); }else if (avctp->cr ==AVCTP_COMMAND && - avrcp->code ==CTYPE_CONTROL && - avrcp->subunit_type ==SUBUNIT_PANEL && - avrcp->opcode ==OP_PASSTHROUGH ) { + avc->code ==CTYPE_CONTROL && + avc->subunit_type ==SUBUNIT_PANEL && + avc->opcode ==OP_PASSTHROUGH ) {handle_panel_passthrough (control, operands, operand_count); avctp->cr =AVCTP_RESPONSE ; - avrcp->code =CTYPE_ACCEPTED ; + avc->code =CTYPE_ACCEPTED ; }else if (avctp->cr ==AVCTP_COMMAND && - avrcp->code ==CTYPE_STATUS && - (avrcp->opcode ==OP_UNITINFO - || avrcp->opcode ==OP_SUBUNITINFO )) { + avc->code ==CTYPE_STATUS && + (avc->opcode ==OP_UNITINFO + || avc->opcode ==OP_SUBUNITINFO )) { avctp->cr =AVCTP_RESPONSE ; - avrcp->code =CTYPE_STABLE ; + avc->code =CTYPE_STABLE ;/* The first operand should be 0x07 for the UNITINFO response. * Neither AVRCP (section 22.1, page 117) nor AVC Digital * Interface Command Set (section 9.2.1, page 45) specs * explain this value but both use it */ -if (operand_count >=1 && avrcp->opcode ==OP_UNITINFO ) +if (operand_count >=1 && avc->opcode ==OP_UNITINFO ) operands[0 ] =0x07 ;if (operand_count >=2 ) operands[1 ] =SUBUNIT_PANEL <<3 ; -DBG ("reply to %s" , avrcp->opcode ==OP_UNITINFO ? +DBG ("reply to %s" , avc->opcode ==OP_UNITINFO ?"OP_UNITINFO" :"OP_SUBUNITINFO" ); }else if (avctp->cr ==AVCTP_COMMAND && - avrcp->opcode ==OP_VENDORDEP ) { + avc->opcode ==OP_VENDORDEP ) {int r_size; operand_count -=3 ; avctp->cr =AVCTP_RESPONSE ; - r_size =handle_vendordep_pdu (control, avctp, avrcp, + r_size =handle_vendordep_pdu (control, avctp, avc, operand_count); packet_size =AVCTP_HEADER_LENGTH + r_size; }else { avctp->cr =AVCTP_RESPONSE ; - avrcp->code =CTYPE_REJECTED ; + avc->code =CTYPE_REJECTED ; } ret =write (sock, buf, packet_size);
@@ -2092,10 +2092,10 @@ static DBusMessage *control_is_connected(DBusConnection *conn,static int avctp_send_passthrough (struct control *control,uint8_t op) { -unsigned char buf[AVCTP_HEADER_LENGTH +AVRCP_HEADER_LENGTH +2 ]; +unsigned char buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH +2 ];struct avctp_header *avctp = (void *) buf; -struct avrcp_header *avrcp = (void *) &buf[AVCTP_HEADER_LENGTH ]; -uint8_t *operands = &buf[AVCTP_HEADER_LENGTH +AVRCP_HEADER_LENGTH ]; +struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH ]; +uint8_t *operands = &buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH ];int sk =g_io_channel_unix_get_fd (control->io);static uint8_t transaction =0 ;
@@ -2106,9 +2106,9 @@ static int avctp_send_passthrough(struct control *control, uint8_t op) avctp->cr =AVCTP_COMMAND ; avctp->pid =htons (AV_REMOTE_SVCLASS_ID ); - avrcp->code =CTYPE_CONTROL ; - avrcp->subunit_type =SUBUNIT_PANEL ; - avrcp->opcode =OP_PASSTHROUGH ; + avc->code =CTYPE_CONTROL ; + avc->subunit_type =SUBUNIT_PANEL ; + avc->opcode =OP_PASSTHROUGH ; operands[0 ] = op &0x7f ; operands[1 ] =0 ;
Signature · 1 line
1.7.6.1
Luiz Augusto von Dentz
maintainerPATCH 3/5 AVRCP: rename avrcp_spec_avc_pdu to avrcp_header
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
Since old avrcp_header got renamed to avc_header now we can use avrcp_header for AVRCP PDUs.
--- audio/control.c | 44 ++++++++++++++++++++++---------------------- 1 files changed, 22 insertions(+), 22 deletions(-)
audio/control.c +22 -22
@@ -221,7 +221,7 @@ struct avc_header { } __attribute__ ((packed));#define AVC_HEADER_LENGTH 3 -struct avrcp_spec_avc_pdu { +struct avrcp_header {uint8_t company_id[3 ];uint8_t pdu_id;uint8_t packet_type:2 ;
@@ -229,7 +229,7 @@ struct avrcp_spec_avc_pdu {uint16_t params_len;uint8_t params[0 ]; } __attribute__ ((packed)); -#define AVRCP_SPECAVCPDU_HEADER_LENGTH 7 +#define AVRCP_HEADER_LENGTH 7#elif __BYTE_ORDER == __BIG_ENDIAN
@@ -251,7 +251,7 @@ struct avc_header { } __attribute__ ((packed));#define AVC_HEADER_LENGTH 3 -struct avrcp_spec_avc_pdu { +struct avrcp_header {uint8_t company_id[3 ];uint8_t pdu_id;uint8_t rsvd:6 ;
@@ -259,7 +259,7 @@ struct avrcp_spec_avc_pdu {uint16_t params_len;uint8_t params[0 ]; } __attribute__ ((packed)); -#define AVRCP_SPECAVCPDU_HEADER_LENGTH 7 +#define AVRCP_HEADER_LENGTH 7#else #error "Unknown byte order"
@@ -722,10 +722,10 @@ static const char *battery_status_to_str(enum battery_status status)static int avctp_send_event (struct control *control,uint8_t id,void *data) {uint8_t buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH + -AVRCP_SPECAVCPDU_HEADER_LENGTH +9 ]; +AVRCP_HEADER_LENGTH +9 ];struct avctp_header *avctp = (void *) buf;struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH ]; -struct avrcp_spec_avc_pdu *pdu = (void *) &buf[AVCTP_HEADER_LENGTH + +struct avrcp_header *pdu = (void *) &buf[AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH ];int sk =g_io_channel_unix_get_fd (control->io);uint16_t size;
@@ -781,7 +781,7 @@ static int avctp_send_event(struct control *control, uint8_t id, void *data) pdu->params_len =htons (size); size +=AVCTP_HEADER_LENGTH +AVC_HEADER_LENGTH + -AVRCP_SPECAVCPDU_HEADER_LENGTH ; +AVRCP_HEADER_LENGTH ; sk =g_io_channel_unix_get_fd (control->io);
@@ -987,7 +987,7 @@ static void mp_set_media_attributes(struct control *control, }static uint8_t avrcp_handle_get_capabilities (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1027,7 +1027,7 @@ err: }static uint8_t avrcp_handle_list_player_attributes (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1061,7 +1061,7 @@ done: }static uint8_t avrcp_handle_list_player_values (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1092,7 +1092,7 @@ err: }static uint8_t avrcp_handle_get_element_attributes (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1161,7 +1161,7 @@ err: }static uint8_t avrcp_handle_get_current_player_value (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1225,7 +1225,7 @@ err: }static uint8_t avrcp_handle_set_player_value (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1278,7 +1278,7 @@ err: }static uint8_t avrcp_handle_displayable_charset (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1298,7 +1298,7 @@ static uint8_t avrcp_handle_displayable_charset(struct control *control, }static uint8_t avrcp_handle_ct_battery_status (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1325,7 +1325,7 @@ err: }static uint8_t avrcp_handle_get_play_status (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1360,7 +1360,7 @@ static uint8_t avrcp_handle_get_play_status(struct control *control, }static uint8_t avrcp_handle_register_notification (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction) {uint16_t len =ntohs (pdu->params_len);
@@ -1418,7 +1418,7 @@ static struct pdu_handler {uint8_t pdu_id;uint8_t code;uint8_t (*func) (struct control *control, -struct avrcp_spec_avc_pdu *pdu, +struct avrcp_header *pdu,uint8_t transaction); } handlers[] = { { AVRCP_GET_CAPABILITIES, CTYPE_STATUS,
@@ -1455,7 +1455,7 @@ static int handle_vendordep_pdu(struct control *control, int operand_count) {struct pdu_handler *handler; -struct avrcp_spec_avc_pdu *pdu = (void *) avc +AVC_HEADER_LENGTH ; +struct avrcp_header *pdu = (void *) avc +AVC_HEADER_LENGTH ;uint32_t company_id = (pdu->company_id[0 ] <<16 ) | (pdu->company_id[1 ] <<8 ) | (pdu->company_id[2 ]);
@@ -1469,7 +1469,7 @@ static int handle_vendordep_pdu(struct control *control, pdu->packet_type =0 ; pdu->rsvd =0 ; -if (operand_count +3 <AVRCP_SPECAVCPDU_HEADER_LENGTH ) +if (operand_count +3 <AVRCP_HEADER_LENGTH ) goto err_metadata;for (handler = handlers; handler; handler++) {
@@ -1489,14 +1489,14 @@ static int handle_vendordep_pdu(struct control *control, avc->code = handler->func (control, pdu, avctp->transaction); -return AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH + +return AVC_HEADER_LENGTH +AVRCP_HEADER_LENGTH +ntohs (pdu->params_len); err_metadata: pdu->params_len =htons (1 ); avc->code =CTYPE_REJECTED ; -return AVC_HEADER_LENGTH +AVRCP_SPECAVCPDU_HEADER_LENGTH +1 ; +return AVC_HEADER_LENGTH +AVRCP_HEADER_LENGTH +1 ; }static void avctp_disconnected (struct audio_device *dev)
Signature · 1 line
1.7.6.1
Luiz Augusto von Dentz
maintainerPATCH 4/5 AVRCP: split AVCTP specific code from control.c
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
The code is moved to avctp.c to simplify control.c
--- Makefile.am | 1 + audio/avctp.c | 1028 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ audio/avctp.h | 95 +++++ audio/control.c | 875 +++++++---------------------------------------- audio/control.h | 14 - audio/device.c | 1 + 6 files changed, 1242 insertions(+), 772 deletions(-) create mode 100644 audio/avctp.c create mode 100644 audio/avctp.h
Makefile.am +1 -0
@@ -143,6 +143,7 @@ builtin_sources += audio/main.c \ audio/gateway.h audio/gateway.c \ audio/headset.h audio/headset.c \ audio/control.h audio/control.c \ + audio/avctp.h audio/avctp.c \ audio/device.h audio/device.c \ audio/source.h audio/source.c \ audio/sink.h audio/sink.c \
audio/avctp.c new file +1028 -0
1,028 lines not on this page · raw message
audio/avctp.h new file +95 -0
95 lines not on this page · raw message
audio/control.c +117 -758
1,308 lines not on this page · raw message
audio/control.h +0 -14
@@ -25,20 +25,6 @@#define AUDIO_CONTROL_INTERFACE "org.bluez.Control"#define MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer" -typedef enum { -AVCTP_STATE_DISCONNECTED =0 , -AVCTP_STATE_CONNECTING , -AVCTP_STATE_CONNECTED -}avctp_state_t ; - -typedef void (*avctp_state_cb ) (struct audio_device *dev, -avctp_state_t old_state, -avctp_state_t new_state, -void *user_data); - -unsigned int avctp_add_state_cb (avctp_state_cb cb,void *user_data); -gboolean avctp_remove_state_cb (unsigned int id); -int avrcp_register (DBusConnection *conn,const bdaddr_t *src,GKeyFile *config);void avrcp_unregister (const bdaddr_t *src);
audio/device.c +1 -0
@@ -52,6 +52,7 @@#include "unix.h" #include "avdtp.h" #include "control.h" +#include "avctp.h" #include "headset.h" #include "gateway.h" #include "sink.h"
Signature · 1 line
1.7.6.1
Luiz Augusto von Dentz
maintainerPATCH 5/5 AVRCP: move handling of vendor dependent PDU from control.c to avrcp.c
In reply to Luiz Augusto von DentzFrom: Luiz Augusto von Dentz <[email protected]>
This helps to isolate AVRCP PDU handling and MediaPlayer interface.
--- Makefile.am | 1 + audio/avctp.c | 5 + audio/avctp.h | 1 + audio/avrcp.c | 1661 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ audio/avrcp.h | 34 ++ audio/control.c | 1636 +------------------------------------------------------ audio/control.h | 13 +- audio/device.c | 4 + audio/device.h | 2 + audio/manager.c | 10 +- 10 files changed, 1720 insertions(+), 1647 deletions(-) create mode 100644 audio/avrcp.c create mode 100644 audio/avrcp.h
Makefile.am +1 -0
@@ -144,6 +144,7 @@ builtin_sources += audio/main.c \ audio/headset.h audio/headset.c \ audio/control.h audio/control.c \ audio/avctp.h audio/avctp.c \ + audio/avrcp.h audio/avrcp.c \ audio/device.h audio/device.c \ audio/source.h audio/source.c \ audio/sink.h audio/sink.c \
audio/avctp.c +5 -0
@@ -1026,3 +1026,8 @@ void avctp_disconnect(struct avctp *session)avctp_set_state (session,AVCTP_STATE_DISCONNECTED ); } + +struct avctp *avctp_get (const bdaddr_t *src,const bdaddr_t *dst) +{ +return avctp_get_internal (src, dst); +}
audio/avctp.h +1 -0
@@ -83,6 +83,7 @@ int avctp_register(const bdaddr_t *src, gboolean master);void avctp_unregister (const bdaddr_t *src);struct avctp *avctp_connect (const bdaddr_t *src,const bdaddr_t *dst); +struct avctp *avctp_get (const bdaddr_t *src,const bdaddr_t *dst);void avctp_disconnect (struct avctp *session); unsigned int avctp_register_pdu_handler(uint8_t opcode, avctp_pdu_cb cb,
audio/avrcp.c new file +1661 -0
1,661 lines not on this page · raw message
audio/avrcp.h new file +34 -0
@@ -0,0 +1,34 @@ +/* +* +* BlueZ - Bluetooth protocol stack for Linux +* +* Copyright (C) 2006-2010 Nokia Corporation +* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]> +* +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +* +*/ + +#define MEDIA_PLAYER_INTERFACE "org.bluez.MediaPlayer" + +int avrcp_register (DBusConnection *conn,const bdaddr_t *src,GKeyFile *config); +void avrcp_unregister (const bdaddr_t *src); + +gboolean avrcp_connect (struct audio_device *dev); +void avrcp_disconnect (struct audio_device *dev); + +struct media_player *media_player_init (struct audio_device *dev); +void media_player_unregister (struct audio_device *dev);
audio/control.c +4 -1632
1,283 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.6.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH BlueZ 2/5] AVRCP: rename avrcp_header to avc_header
In reply to Luiz Augusto von DentzHi Luiz
Quoted 7 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
AVCTP carries AV/C packets/PDUs not AVRCP as
avrcp_headersuggests.
---
audio/control.c | 98 +++++++++++++++++++++++++++---------------------------1 files changed, 49 insertions(+), 49 deletions(-)
This was the next one in my TODO list. I'm glad you did it :-)
Quoted 49 lines
audio/control.c +6
-6@@ -212,14 +212,14 @@ struct avctp_header { } __attribute__ ((packed)); #define AVCTP_HEADER_LENGTH 3 -struct avrcp_header { +struct avc_header { uint8_t code:4; uint8_t _hdr0:4; uint8_t subunit_id:3; uint8_t subunit_type:5; uint8_t opcode; } __attribute__ ((packed)); -#define AVRCP_HEADER_LENGTH 3 +#define AVC_HEADER_LENGTH 3 struct avrcp_spec_avc_pdu { uint8_t company_id[3];@@ -242,14 +242,14 @@ struct avctp_header { } __attribute__ ((packed)); #define AVCTP_HEADER_LENGTH 3 -struct avrcp_header { +struct avc_header { uint8_t _hdr0:4; uint8_t code:4; uint8_t subunit_type:5; uint8_t subunit_id:3; uint8_t opcode; } __attribute__ ((packed)); -#define AVRCP_HEADER_LENGTH 3 +#define AVC_HEADER_LENGTH 3 struct avrcp_spec_avc_pdu { uint8_t company_id[3];@@ -721,13 +721,13 @@ static const char *battery_status_to_str(enum battery_status status) static int avctp_send_event(struct control *control, uint8_t id, void *data) { - uint8_t buf[AVCTP_HEADER_LENGTH + AVRCP_HEADER_LENGTH + + uint8_t buf[AVCTP_HEADER_LENGTH + AVC_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH + 9]; struct avctp_header *avctp = (void *) buf; - struct avrcp_header *avrcp = (void *) &buf[AVCTP_HEADER_LENGTH]; + struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH];
Quoted 5 lines
struct
avrcp_spec_avc_pdu*pdu = (void *) &buf[AVCTP_HEADER_LENGTH +
-AVRCP_HEADER_LENGTH];
- int sk;
+AVC_HEADER_LENGTH];
+ int sk =g_io_channel_unix_get_fd(control->io);
You are re-introducing a bug here. Please see "dec26ee Fix fd usage when not connected"
Quoted 26 lines
uint16_t size;
if (
control->state!=AVCTP_STATE_CONNECTED)audio/control.c +4
-4@@ -743,9 +743,9 @@ static int avctp_send_event(struct control *control, uint8_t id, void *data) avctp->cr = AVCTP_RESPONSE; avctp->pid = htons(AV_REMOTE_SVCLASS_ID); - avrcp->code = CTYPE_CHANGED; - avrcp->subunit_type = SUBUNIT_PANEL; - avrcp->opcode = OP_VENDORDEP; + avc->code = CTYPE_CHANGED; + avc->subunit_type = SUBUNIT_PANEL; + avc->opcode = OP_VENDORDEP; pdu->company_id[0] = IEEEID_BTSIG >> 16; pdu->company_id[1] = (IEEEID_BTSIG >> 8) & 0xFF;@@ -780,7 +780,7 @@ static int avctp_send_event(struct control *control, uint8_t id, void *data) } pdu->params_len = htons(size); - size += AVCTP_HEADER_LENGTH + AVRCP_HEADER_LENGTH + + size += AVCTP_HEADER_LENGTH + AVC_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH; sk = g_io_channel_unix_get_fd(control->io);
audio/control.c static struct pdu_handler { · line 1458
Quoted 10 lines
audio/control.c +2
-2@@ -1451,19 +1451,19 @@ static struct pdu_handler { /* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu(struct control *control, struct avctp_header *avctp, - struct avrcp_header *avrcp, + struct avc_header *avc, int operand_count) { struct pdu_handler *handler; - struct avrcp_spec_avc_pdu *pdu = (void *) avrcp + AVRCP_HEADER_LENGTH; + struct avrcp_spec_avc_pdu *pdu = (void *) avc + AVC_HEADER_LENGTH;
We might want to change this to:
struct avrcp_spec_avc_pdu *pdu = (avrcp_spec_avc_pdu *)(avc + AVC_HEADER_LENGTH);
This way we kill some warnings on ARM: arithmetic with void pointer
Quoted 157 lines
uint32_t
company_id= (pdu->company_id[0] << 16) | (pdu->company_id[1] << 8) | (pdu->company_id[2]);if (
company_id!=IEEEID_BTSIG||
pdu->packet_type !=AVCTP_PACKET_SINGLE) {
-avrcp->code=CTYPE_NOT_IMPLEMENTED;
- returnAVRCP_HEADER_LENGTH;
+avc->code=CTYPE_NOT_IMPLEMENTED;
+ returnAVC_HEADER_LENGTH;
}pdu->packet_type = 0;
audio/control.c +3
-3@@ -1477,7 +1477,7 @@ static int handle_vendordep_pdu(struct control *control, break; } - if (!handler || handler->code != avrcp->code) { + if (!handler || handler->code != avc->code) { pdu->params[0] = E_INVALID_COMMAND; goto err_metadata; }@@ -1487,16 +1487,16 @@ static int handle_vendordep_pdu(struct control *control, goto err_metadata; } - avrcp->code = handler->func(control, pdu, avctp->transaction); + avc->code = handler->func(control, pdu, avctp->transaction); - return AVRCP_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH + + return AVC_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH + ntohs(pdu->params_len);err_metadata:
pdu->params_len = htons(1);
-avrcp->code=CTYPE_REJECTED;
+avc->code=CTYPE_REJECTED;- return
AVRCP_HEADER_LENGTH+AVRCP_SPECAVCPDU_HEADER_LENGTH+ 1;
+ returnAVC_HEADER_LENGTH+AVRCP_SPECAVCPDU_HEADER_LENGTH+ 1; }static void
avctp_disconnected(struct audio_device *dev)audio/control.c +25
-25@@ -1593,7 +1593,7 @@ static gboolean control_cb(GIOChannel *chan, GIOCondition cond, struct control *control = data; unsigned char buf[1024], *operands; struct avctp_header *avctp; - struct avrcp_header *avrcp; + struct avc_header *avc; int ret, packet_size, operand_count, sock; if (cond & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))@@ -1622,65 +1622,65 @@ static gboolean control_cb(GIOChannel *chan, GIOCondition cond, avctp->cr, avctp->ipid, ntohs(avctp->pid)); ret -= sizeof(struct avctp_header); - if ((unsigned int) ret < sizeof(struct avrcp_header)) { + if ((unsigned int) ret < sizeof(struct avc_header)) { error("Too small AVRCP packet"); goto failed; } - avrcp = (struct avrcp_header *) (buf + sizeof(struct avctp_header)); + avc = (struct avc_header *) (buf + sizeof(struct avctp_header)); - ret -= sizeof(struct avrcp_header); + ret -= sizeof(struct avc_header); - operands = buf + sizeof(struct avctp_header) + sizeof(struct avrcp_header); + operands = buf + sizeof(struct avctp_header) + sizeof(struct avc_header); operand_count = ret; - DBG("AVRCP %s 0x%01X, subunit_type 0x%02X, subunit_id 0x%01X, " + DBG("AV/C %s 0x%01X, subunit_type 0x%02X, subunit_id 0x%01X, " "opcode 0x%02X, %d operands", avctp->cr ? "response" : "command", - avrcp->code, avrcp->subunit_type, avrcp->subunit_id, - avrcp->opcode, operand_count); + avc->code, avc->subunit_type, avc->subunit_id, + avc->opcode, operand_count); if (avctp->packet_type != AVCTP_PACKET_SINGLE) { avctp->cr = AVCTP_RESPONSE; - avrcp->code = CTYPE_NOT_IMPLEMENTED; + avc->code = CTYPE_NOT_IMPLEMENTED; } else if (avctp->pid != htons(AV_REMOTE_SVCLASS_ID)) { avctp->ipid = 1; avctp->cr = AVCTP_RESPONSE; packet_size = sizeof(*avctp); } else if (avctp->cr == AVCTP_COMMAND && - avrcp->code == CTYPE_CONTROL && - avrcp->subunit_type == SUBUNIT_PANEL && - avrcp->opcode == OP_PASSTHROUGH) { + avc->code == CTYPE_CONTROL && + avc->subunit_type == SUBUNIT_PANEL && + avc->opcode == OP_PASSTHROUGH) { handle_panel_passthrough(control, operands, operand_count); avctp->cr = AVCTP_RESPONSE; - avrcp->code = CTYPE_ACCEPTED; + avc->code = CTYPE_ACCEPTED; } else if (avctp->cr == AVCTP_COMMAND && - avrcp->code == CTYPE_STATUS && - (avrcp->opcode == OP_UNITINFO - || avrcp->opcode == OP_SUBUNITINFO)) { + avc->code == CTYPE_STATUS && + (avc->opcode == OP_UNITINFO + || avc->opcode == OP_SUBUNITINFO)) { avctp->cr = AVCTP_RESPONSE; - avrcp->code = CTYPE_STABLE; + avc->code = CTYPE_STABLE; /* The first operand should be 0x07 for the UNITINFO response. * Neither AVRCP (section 22.1, page 117) nor AVC Digital * Interface Command Set (section 9.2.1, page 45) specs * explain this value but both use it */ - if (operand_count >= 1 && avrcp->opcode == OP_UNITINFO) + if (operand_count >= 1 && avc->opcode == OP_UNITINFO) operands[0] = 0x07; if (operand_count >= 2) operands[1] = SUBUNIT_PANEL << 3; - DBG("reply to %s", avrcp->opcode == OP_UNITINFO ? + DBG("reply to %s", avc->opcode == OP_UNITINFO ? "OP_UNITINFO" : "OP_SUBUNITINFO"); } else if (avctp->cr == AVCTP_COMMAND && - avrcp->opcode == OP_VENDORDEP) { + avc->opcode == OP_VENDORDEP) { int r_size; operand_count -= 3; avctp->cr = AVCTP_RESPONSE; - r_size = handle_vendordep_pdu(control, avctp, avrcp, + r_size = handle_vendordep_pdu(control, avctp, avc, operand_count); packet_size = AVCTP_HEADER_LENGTH + r_size; } else { avctp->cr = AVCTP_RESPONSE; - avrcp->code = CTYPE_REJECTED; + avc->code = CTYPE_REJECTED; } ret = write(sock, buf, packet_size);@@ -2092,10 +2092,10 @@ static DBusMessage *control_is_connected(DBusConnection *conn, static int avctp_send_passthrough(struct control *control, uint8_t op) { - unsigned char buf[AVCTP_HEADER_LENGTH + AVRCP_HEADER_LENGTH + 2]; + unsigned char buf[AVCTP_HEADER_LENGTH + AVC_HEADER_LENGTH + 2]; struct avctp_header *avctp = (void *) buf; - struct avrcp_header *avrcp = (void *) &buf[AVCTP_HEADER_LENGTH]; - uint8_t *operands = &buf[AVCTP_HEADER_LENGTH + AVRCP_HEADER_LENGTH]; + struct avc_header *avc = (void *) &buf[AVCTP_HEADER_LENGTH]; + uint8_t *operands = &buf[AVCTP_HEADER_LENGTH + AVC_HEADER_LENGTH]; int sk = g_io_channel_unix_get_fd(control->io); static uint8_t transaction = 0;@@ -2106,9 +2106,9 @@ static int avctp_send_passthrough(struct control *control, uint8_t op) avctp->cr = AVCTP_COMMAND; avctp->pid = htons(AV_REMOTE_SVCLASS_ID);
audio/control.c static int avctp_send_passthrough(struct control *control, uint8_t op)
Quoted 10 lines
audio/control.c +3
-4- avrcp->code = CTYPE_CONTROL; - avrcp->subunit_type = SUBUNIT_PANEL; - avrcp->opcode = OP_PASSTHROUGH; + avc->code = CTYPE_CONTROL; + avc->subunit_type = SUBUNIT_PANEL; + avc->opcode = OP_PASSTHROUGH; operands[0] = op & 0x7f; operands[1] = 0; --
The rest looks good to me.
Lucas De Marchi
Quoted 49 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
This simplify a bit the handling by introducing common checks before calling the handler callback, it is also much easier to add/remove new PDUs in this way.
---
audio/control.c | 321 +++++++++++++++++++++----------------------------------1 files changed, 124 insertions(+), 197 deletions(-)audio/control.c +4
-3@@ -986,8 +986,9 @@ static void mp_set_media_attributes(struct control *control, avctp_send_event(control, AVRCP_EVENT_TRACK_CHANGED, NULL); } -static int avrcp_handle_get_capabilities (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_capabilities (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction) { uint16_t len = ntohs(pdu->params_len); unsigned int i;@@ -1008,31 +1009,35 @@ static int avrcp_handle_get_capabilities(struct control *control, pdu->params_len = htons(2 + (3 * G_N_ELEMENTS(company_ids))); pdu->params[1] = G_N_ELEMENTS(company_ids); - return 2 + (3 * G_N_ELEMENTS(company_ids)); + return CTYPE_STABLE;case
CAP_EVENTS_SUPPORTED:
pdu->params_len = htons(4);
pdu->params[1] = 2;
pdu->params[2] =AVRCP_EVENT_PLAYBACK_STATUS_CHANGED; pdu->params[3] =AVRCP_EVENT_TRACK_CHANGED;- return 4;
+ returnCTYPE_STABLE;
}err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+
+ returnCTYPE_REJECTED;
}
audio/control.c static int avrcp_handle_get_capabilities(struct control *control, · line 1031
Quoted 5 lines
audio/control.c +3
-2-static int avrcp_handle_list_player_attributes (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_list_player_attributes (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction)
It might be my CFLAGS, but aren't you getting warnings of unused parameters since now every handler carries the transaction id?
Quoted 441 lines
{
uint16_t len =ntohs(pdu->params_len);
structmedia_player*mp =control->mp;
unsigned int i;if (len != 0) {
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}if (!mp)
audio/control.c +5
-4@@ -1052,11 +1057,12 @@ done: pdu->params[0] = len; pdu->params_len = htons(len + 1); - return len + 1; + return CTYPE_STABLE; } -static int avrcp_handle_list_player_values (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_list_player_values (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction) { uint16_t len = ntohs(pdu->params_len); struct media_player *mp = control->mp;@@ -1077,15 +1083,17 @@ static int avrcp_handle_list_player_values(struct control *control, pdu->params[0] = len; pdu->params_len = htons(len + 1); - return len + 1; + return CTYPE_STABLE;err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +3
-2-static int avrcp_handle_get_element_attributes (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_element_attributes (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction){
uint16_t len =ntohs(pdu->params_len);uint64_t*identifier = (void *) &pdu->params[0];audio/control.c +1
-1@@ -1145,14 +1153,16 @@ done: pdu->params[0] = len; pdu->params_len = htons(pos); - return pos; + return CTYPE_STABLE;err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +3
-2-static int avrcp_handle_get_current_player_value (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_current_player_value (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction){
uint16_t len =ntohs(pdu->params_len);
structmedia_player*mp =control->mp;audio/control.c +1
-1@@ -1202,19 +1212,21 @@ static int avrcp_handle_get_current_player_value(struct control *control, pdu->params[0] = len; pdu->params_len = htons(2 * len + 1); - return 2 * len + 1; + return CTYPE_STABLE; } error("No valid attributes in request");err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;- return
-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +3
-2-static int avrcp_handle_set_player_value (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_set_player_value (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction){
uint16_t len =ntohs(pdu->params_len);
unsigned int i;audio/control.c +1
-1@@ -1256,16 +1268,38 @@ static int avrcp_handle_set_player_value(struct control *control, if (len) { pdu->params_len = 0; - return 0; + return CTYPE_STABLE; }err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +23
-2-static int avrcp_handle_ct_battery_status (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_displayable_charset (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction) +{ + uint16_t len = ntohs(pdu->params_len); + + if (len < 3) { + pdu->params_len = htons(1); + pdu->params[0] = E_INVALID_PARAM; + return CTYPE_REJECTED; + } + + /* + * We acknowledge the commands, but we always use UTF-8 for + * encoding since CT is obliged to support it. + */ + pdu->params_len = 0; + return CTYPE_STABLE; +} + +static uint8_t avrcp_handle_ct_battery_status (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction){
uint16_t len =ntohs(pdu->params_len);
const char *valstr;audio/control.c +1
-1@@ -1282,15 +1316,17 @@ static int avrcp_handle_ct_battery_status(struct control *control, DBUS_TYPE_STRING, &valstr); pdu->params_len = 0; - return 0; + return CTYPE_STABLE;err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +3
-2-static int avrcp_handle_get_play_status (struct control *control, - struct avrcp_spec_avc_pdu *pdu) +static uint8_t avrcp_handle_get_play_status (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction){
uint16_t len =ntohs(pdu->params_len);
uint32_t elapsed;audio/control.c +5
-4@@ -1298,8 +1334,9 @@ static int avrcp_handle_get_play_status(struct control *control, uint8_t status; if (len != 0) { + pdu->params_len = htons(1); pdu->params[0] = E_INVALID_PARAM; - return -EINVAL; + return CTYPE_REJECTED; } if (control->mp) {@@ -1319,10 +1356,10 @@ static int avrcp_handle_get_play_status(struct control *control, pdu->params_len = htons(9); - return 9; + return CTYPE_STABLE; } -static int avrcp_handle_register_notification (struct control *control, +static uint8_t avrcp_handle_register_notification (struct control *control, struct avrcp_spec_avc_pdu *pdu, uint8_t transaction) {@@ -1369,24 +1406,59 @@ static int avrcp_handle_register_notification(struct control *control, pdu->params_len = htons(len); - return len; + return CTYPE_INTERIM;err:
+pdu->params_len= htons(1);
pdu->params[0] =E_INVALID_PARAM;
- return-EINVAL;
+ returnCTYPE_REJECTED;
}audio/control.c +34
-0+static struct pdu_handler { + uint8_t pdu_id; + uint8_t code; + uint8_t (*func) (struct control *control, + struct avrcp_spec_avc_pdu *pdu, + uint8_t transaction); +} handlers[] = { + { AVRCP_GET_CAPABILITIES, CTYPE_STATUS, + avrcp_handle_get_capabilities }, + { AVRCP_LIST_PLAYER_ATTRIBUTES, CTYPE_STATUS, + avrcp_handle_list_player_attributes }, + { AVRCP_LIST_PLAYER_VALUES, CTYPE_STATUS, + avrcp_handle_list_player_values }, + { AVRCP_GET_ELEMENT_ATTRIBUTES, CTYPE_STATUS, + avrcp_handle_get_element_attributes }, + { AVRCP_GET_CURRENT_PLAYER_VALUE, CTYPE_STATUS, + avrcp_handle_get_current_player_value }, + { AVRCP_SET_PLAYER_VALUE, CTYPE_CONTROL, + avrcp_handle_set_player_value }, + { AVRCP_GET_PLAYER_ATTRIBUTE_TEXT, CTYPE_STATUS, + NULL }, + { AVRCP_GET_PLAYER_VALUE_TEXT, CTYPE_STATUS, + NULL }, + { AVRCP_DISPLAYABLE_CHARSET, CTYPE_STATUS, + avrcp_handle_displayable_charset }, + { AVRCP_CT_BATTERY_STATUS, CTYPE_STATUS, + avrcp_handle_ct_battery_status }, + { AVRCP_GET_PLAY_STATUS, CTYPE_STATUS, + avrcp_handle_get_play_status }, + { AVRCP_REGISTER_NOTIFICATION, CTYPE_NOTIFY, + avrcp_handle_register_notification }, + { }, +}; +/* handle vendordep pdu inside an avctp packet */
static int handle_vendordep_pdu(struct control *control,
structavctp_header*avctp, structavrcp_header*avrcp, intoperand_count)
{
+ structpdu_handler*handler;
structavrcp_spec_avc_pdu*pdu = (void *) avrcp +AVRCP_HEADER_LENGTH;uint32_tcompany_id= (pdu->company_id[0] << 16) | (pdu->company_id[1] << 8) | (pdu->company_id[2]);
- int len;if (
company_id!=IEEEID_BTSIG||
pdu->packet_type !=AVCTP_PACKET_SINGLE) {audio/control.c +14
-159@@ -1397,177 +1469,32 @@ static int handle_vendordep_pdu(struct control *control, pdu->packet_type = 0; pdu->rsvd = 0; - if (operand_count + 3 < AVRCP_SPECAVCPDU_HEADER_LENGTH) { - pdu->params[0] = E_INVALID_COMMAND; + if (operand_count + 3 < AVRCP_SPECAVCPDU_HEADER_LENGTH) goto err_metadata; - } - - switch (pdu->pdu_id) { - case AVRCP_GET_CAPABILITIES: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_get_capabilities(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_LIST_PLAYER_ATTRIBUTES: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - len = avrcp_handle_list_player_attributes(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_LIST_PLAYER_VALUES: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_list_player_values(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_GET_ELEMENT_ATTRIBUTES: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_get_element_attributes(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_GET_CURRENT_PLAYER_VALUE: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_get_current_player_value(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_SET_PLAYER_VALUE: - if (avrcp->code != CTYPE_CONTROL) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_set_player_value(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_GET_PLAYER_ATTRIBUTE_TEXT: - case AVRCP_GET_PLAYER_VALUE_TEXT: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } + for (handler = handlers; handler; handler++) { + if (handler->pdu_id == pdu->pdu_id) + break; + } - /* - * As per sec. 5.2.5 of AVRCP 1.3 spec, this command is - * expected to be used only for extended attributes, i.e. - * custom attributes defined by the application. As we - * currently don't have any such attribute, we respond with - * invalid param id. - */ - pdu->params[0] = E_INVALID_PARAM; + if (!handler || handler->code != avrcp->code) { + pdu->params[0] = E_INVALID_COMMAND; goto err_metadata; - case AVRCP_DISPLAYABLE_CHARSET: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - if (pdu->params[0] < 3) { - pdu->params[0] = E_INVALID_PARAM; - goto err_metadata; - } - - /* - * We acknowledge the commands, but we always use UTF-8 for - * encoding since CT is obliged to support it. - */ - pdu->params_len = 0; - avrcp->code = CTYPE_STABLE; - len = 0; - - break; - case AVRCP_CT_BATTERY_STATUS: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_ct_battery_status(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_GET_PLAY_STATUS: - if (avrcp->code != CTYPE_STATUS) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_get_play_status(control, pdu); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_STABLE; - - break; - case AVRCP_REGISTER_NOTIFICATION: - if (avrcp->code != CTYPE_NOTIFY) { - pdu->params[0] = E_INVALID_COMMAND; - goto err_metadata; - } - - len = avrcp_handle_register_notification(control, pdu, - avctp->transaction); - if (len < 0) - goto err_metadata; - - avrcp->code = CTYPE_INTERIM; + } - break; - default: - /* Invalid pdu_id */ - pdu->params[0] = E_INVALID_COMMAND; + if (!handler->func) { + pdu->params[0] = E_INVALID_PARAM; goto err_metadata; } - return AVRCP_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH + len; + avrcp->code = handler->func(control, pdu, avctp->transaction); + + return AVRCP_HEADER_LENGTH + AVRCP_SPECAVCPDU_HEADER_LENGTH + + ntohs(pdu->params_len);err_metadata:
-avrcp->code=CTYPE_REJECTED;
pdu->params_len = htons(1);
+avrcp->code=CTYPE_REJECTED;
Quoted 2 lines
return
AVRCP_HEADER_LENGTH+AVRCP_SPECAVCPDU_HEADER_LENGTH+ 1; }
Otherwise looks good.
Lucas De Marchi
Re: [PATCH BlueZ 2/5] AVRCP: rename avrcp_header to avc_header
In reply to Lucas De MarchiQuoted 17 lines
Hi Luiz
audio/control.c static struct pdu_handler { · line 1458
Quoted 12 lines
sk = g_io_channel_unix_get_fd(control->io);audio/control.c +2
-2@@ -1451,19 +1451,19 @@ static struct pdu_handler {/* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu (struct control *control,struct avctp_header *avctp, -struct avrcp_header *avrcp, +struct avc_header *avc,int operand_count) {struct pdu_handler *handler; -struct avrcp_spec_avc_pdu *pdu = (void *) avrcp +AVRCP_HEADER_LENGTH ; +struct avrcp_spec_avc_pdu *pdu = (void *) avc +AVC_HEADER_LENGTH ;We might want to change this to:
Quoted 2 lines
struct
avrcp_spec_avc_pdu*pdu = (avrcp_spec_avc_pdu*)(avc +AVC_HEADER_LENGTH);
I don't think this is correct, that would result in jumping 5 * (sizeof (struct avc_header)) bytes..
Quoted 1 line
This way we kill some warnings on ARM: arithmetic with void pointer
This should happen only if compiling with -Wpointer-arith or -pedantic.
Signature · 2 lines
BR Szymon Janc
Re: [PATCH BlueZ 3/5] AVRCP: rename avrcp_spec_avc_pdu to avrcp_header
In reply to Luiz Augusto von DentzQuoted 7 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
Since old
avrcp_headergot renamed toavc_headernow we can useavrcp_headerfor AVRCP PDUs.
---
audio/control.c | 44 ++++++++++++++++++++++----------------------1 files changed, 22 insertions(+), 22 deletions(-)
ack
Lucas De Marchi
Luiz Augusto von Dentz
maintainerHi Lucas,
Quoted 2 lines · Lucas De Marchi
It might be my CFLAGS, but aren't you getting warnings of unused parameters since now every handler carries the transaction id?
Nope and Im not sure why checking unused parameter would be a nice thing to have, specially dummy callbacks normally ignores some/all the parameters.
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 2/5] AVRCP: rename avrcp_header to avc_header
In reply to Lucas De MarchiHi Lucas,
Quoted 6 lines · Lucas De Marchi
Quoted 3 lines
- int sk;
+AVC_HEADER_LENGTH];
+ int sk =g_io_channel_unix_get_fd(control->io);You are re-introducing a bug here. Please see "dec26ee Fix fd usage when not connected"
Must have reintroduced it when I was rebasing it, gonna fix it.
Quoted 9 lines
Quoted 2 lines
+ struct
avrcp_spec_avc_pdu*pdu = (void *) avc +AVC_HEADER_LENGTH;We might want to change this to:
struct
avrcp_spec_avc_pdu*pdu = (avrcp_spec_avc_pdu*)(avc +AVC_HEADER_LENGTH);This way we kill some warnings on ARM: arithmetic with void pointer
Don't remember seeing any problem with it, but anyway it is not something Im introducing.
Signature · 1 line
Luiz Augusto von Dentz
Quoted 11 lines · Luiz Augusto von Dentz
Hi Lucas,
Quoted 2 lines · Lucas De Marchi
It might be my CFLAGS, but aren't you getting warnings of unused parameters since now every handler carries the transaction id?
Nope and Im not sure why checking unused parameter would be a nice thing to have, specially dummy callbacks normally ignores some/all the parameters.
Right, I've just checked the file acinclude.m4 and BlueZ uses "-Wno-unused-parameter" in its CFLAGS.
It's fine, then.
Lucas De Marchi
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 2/5] AVRCP: rename avrcp_header to avc_header
In reply to Szymon JancHi Szymon,
Quoted 17 lines · Szymon Janc
Quoted 17 lines
Hi Luiz
audio/control.c static struct pdu_handler { · line 1458
Quoted 12 lines
sk =
g_io_channel_unix_get_fd(control->io);audio/control.c +2
-2@@ -1451,19 +1451,19 @@ static struct pdu_handler { /* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu(struct control *control, struct avctp_header *avctp, - struct avrcp_header *avrcp, + struct avc_header *avc, int operand_count) { struct pdu_handler *handler; - struct avrcp_spec_avc_pdu *pdu = (void *) avrcp + AVRCP_HEADER_LENGTH; + struct avrcp_spec_avc_pdu *pdu = (void *) avc + AVC_HEADER_LENGTH;We might want to change this to:
Quoted 5 lines
Quoted 2 lines
struct
avrcp_spec_avc_pdu*pdu = (avrcp_spec_avc_pdu*)(avc +AVC_HEADER_LENGTH);I don't think this is correct, that would result in jumping 5 * (sizeof (struct
avc_header)) bytes..
I fail to see how the multiplication got into you equation, but anyway I would prefer using something like this (void *) &avc[AVC_HEADER_LENGTH], but that should be a different patch.
Quoted 3 lines
Quoted 1 line
This way we kill some warnings on ARM: arithmetic with void pointer
This should happen only if compiling with -Wpointer-arith or -pedantic.
I don't think we use those.
Signature · 1 line
Luiz Augusto von Dentz
Luiz Augusto von Dentz
maintainerRe: [PATCH BlueZ 2/5] AVRCP: rename avrcp_header to avc_header
Hi Szymon,
Quoted 23 lines · Luiz Augusto von Dentz
Hi Szymon,
Quoted 20 lines · Szymon Janc
Quoted 19 lines
Hi Luiz
audio/control.c static struct pdu_handler { · line 1458
Quoted 12 lines
sk =
g_io_channel_unix_get_fd(control->io);audio/control.c +2
-2@@ -1451,19 +1451,19 @@ static struct pdu_handler { /* handle vendordep pdu inside an avctp packet */ static int handle_vendordep_pdu(struct control *control, struct avctp_header *avctp, - struct avrcp_header *avrcp, + struct avc_header *avc, int operand_count) { struct pdu_handler *handler; - struct avrcp_spec_avc_pdu *pdu = (void *) avrcp + AVRCP_HEADER_LENGTH; + struct avrcp_spec_avc_pdu *pdu = (void *) avc + AVC_HEADER_LENGTH;We might want to change this to:
struct
avrcp_spec_avc_pdu*pdu = (avrcp_spec_avc_pdu*)(avc +AVC_HEADER_LENGTH);
Quoted 6 lines
Quoted 2 lines
I don't think this is correct, that would result in jumping 5 * (sizeof (struct
avc_header)) bytes..I fail to see how the multiplication got into you equation, but anyway I would prefer using something like this (void *) &avc[AVC_HEADER_LENGTH], but that should be a different patch.
Somebody (Thanks Hendrik), just point out this is wrong as much it was wrong before and indeed it does the multiplication due to avc type (I really failed to see that), anyway this will gonna away with other cleanups since basically the callback receives a pointer to beginning of the PDU in the callback (operands):
typedef size_t (*avctp_pdu_cb) (struct avctp *session, uint8_t transaction,
uint8_t *code, uint8_t *subunit, uint8_t *operands, size_t operand_count, void *user_data);
Signature · 1 line
Luiz Augusto von Dentz