2017-06-14 14:32:51 +02:00
/*
* Copyright ( C ) 2016 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions
* are met :
*
* 1. Redistributions of source code must retain the above copyright
* notice , this list of conditions and the following disclaimer .
* 2. 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 .
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission .
* 4. Any redistribution , use , or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain .
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ` ` AS IS ' ' AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT
* LIMITED TO , THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT SHALL MATTHIAS
* RINGWALD 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 .
*
* Please inquire about commercial licensing options at
* contact @ bluekitchen - gmbh . com
*
*/
# include <stdint.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
2017-07-12 16:35:01 +02:00
# include "btstack.h"
2017-06-14 14:32:51 +02:00
# define AVRCP_BROWSING_ENABLED 0
# ifdef HAVE_BTSTACK_STDIN
# include "btstack_stdin.h"
# endif
# ifdef HAVE_BTSTACK_STDIN
2017-07-12 16:35:01 +02:00
// mac 2011: static const char * device_addr_string = "04:0C:CE:E4:85:D3";
// pts:
2017-06-14 14:32:51 +02:00
static const char * device_addr_string = " 00:1B:DC:08:0A:A5 " ;
2017-07-12 16:35:01 +02:00
// mac 2013: static const char * device_addr_string = "84:38:35:65:d1:15";
// phone 2013: static const char * device_addr_string = "D8:BB:2C:DF:F0:F2";
// minijambox: static const char * device_addr_string = "00:21:3C:AC:F7:38";
// head phones: static const char * device_addr_string = "00:18:09:28:50:18";
// bt dongle: static const char * device_addr_string = "00:15:83:5F:9D:46";
2017-06-14 14:32:51 +02:00
# endif
2017-07-12 16:35:01 +02:00
static bd_addr_t device_addr ;
2017-06-14 14:32:51 +02:00
static btstack_packet_callback_registration_t hci_event_callback_registration ;
static bd_addr_t device_addr ;
static uint8_t sdp_avdtp_sink_service_buffer [ 150 ] ;
static uint8_t sdp_avrcp_controller_service_buffer [ 200 ] ;
static uint16_t avdtp_cid = 0 ;
static avdtp_sep_t sep ;
static avdtp_stream_endpoint_t * local_stream_endpoint ;
2017-07-12 16:35:01 +02:00
static avdtp_context_t a2dp_sink_context ;
2017-06-14 14:32:51 +02:00
static uint16_t avrcp_cid = 0 ;
static void packet_handler ( uint8_t packet_type , uint16_t channel , uint8_t * packet , uint16_t size ) {
2017-07-13 14:35:07 +02:00
if ( packet_type ! = HCI_EVENT_PACKET ) return ;
2017-06-14 14:32:51 +02:00
UNUSED ( channel ) ;
UNUSED ( size ) ;
bd_addr_t event_addr ;
uint16_t local_cid ;
uint8_t status = 0xFF ;
2017-07-13 14:35:07 +02:00
switch ( hci_event_packet_get_type ( packet ) ) {
case HCI_EVENT_AVDTP_META :
switch ( packet [ 2 ] ) {
case AVDTP_SUBEVENT_SIGNALING_CONNECTION_ESTABLISHED :
avdtp_cid = avdtp_subevent_signaling_connection_established_get_avdtp_cid ( packet ) ;
status = avdtp_subevent_signaling_connection_established_get_status ( packet ) ;
if ( status ! = ERROR_CODE_SUCCESS ) {
printf ( " AVDTP connection establishment failed: status 0x%02x. \n " , status ) ;
break ;
2017-06-14 14:32:51 +02:00
}
2017-07-13 14:35:07 +02:00
printf ( " AVDTP connection established: avdtp_cid 0x%02x. \n " , avdtp_cid ) ;
break ;
case AVDTP_SUBEVENT_SIGNALING_CONNECTION_RELEASED :
avdtp_cid = avdtp_subevent_signaling_connection_released_get_avdtp_cid ( packet ) ;
printf ( " AVDTP connection released: avdtp_cid 0x%02x. \n " , avdtp_cid ) ;
break ;
default :
printf ( " AVDTP event not parsed. \n " ) ;
break ;
}
break ;
case HCI_EVENT_AVRCP_META :
switch ( packet [ 2 ] ) {
case AVRCP_SUBEVENT_CONNECTION_ESTABLISHED : {
status = avrcp_subevent_connection_established_get_status ( packet ) ;
avrcp_subevent_connection_established_get_bd_addr ( packet , event_addr ) ;
if ( status ! = ERROR_CODE_SUCCESS ) {
printf ( " AVRCP connection establishment failed: status 0x%02x \n " , status ) ;
avrcp_cid = 0 ;
return ;
}
local_cid = avrcp_subevent_connection_established_get_avrcp_cid ( packet ) ;
if ( avrcp_cid ! = 0 & & avrcp_cid ! = local_cid ) {
printf ( " AVRCP connection establishment failed: expected avrcp_cid 0x%02X, received 0x%02X \n " , avrcp_cid , local_cid ) ;
return ;
}
avrcp_cid = local_cid ;
printf ( " AVRCP connection established: %s, avrcp_cid 0x%02x \n " , bd_addr_to_str ( event_addr ) , avrcp_cid ) ;
return ;
}
case AVRCP_SUBEVENT_CONNECTION_RELEASED :
printf ( " AVRCP connection released: avrcp_cid 0x%02x \n " , avrcp_subevent_connection_released_get_avrcp_cid ( packet ) ) ;
avrcp_cid = 0 ;
return ;
2017-06-14 14:32:51 +02:00
default :
break ;
}
2017-07-13 14:35:07 +02:00
local_cid = little_endian_read_16 ( packet , 3 ) ;
if ( local_cid ! = avrcp_cid ) return ;
// avoid printing INTERIM status
status = packet [ 5 ] ;
if ( status = = AVRCP_CTYPE_RESPONSE_INTERIM ) return ;
printf ( " AVRCP: command status: %s, " , avrcp_ctype2str ( status ) ) ;
switch ( packet [ 2 ] ) {
case AVRCP_SUBEVENT_NOTIFICATION_PLAYBACK_STATUS_CHANGED :
printf ( " notification, playback status changed %s \n " , avrcp_play_status2str ( avrcp_subevent_notification_playback_status_changed_get_play_status ( packet ) ) ) ;
return ;
case AVRCP_SUBEVENT_NOTIFICATION_NOW_PLAYING_CONTENT_CHANGED :
printf ( " notification, playing content changed \n " ) ;
return ;
case AVRCP_SUBEVENT_NOTIFICATION_TRACK_CHANGED :
printf ( " notification track changed \n " ) ;
return ;
case AVRCP_SUBEVENT_NOTIFICATION_VOLUME_CHANGED :
printf ( " notification absolute volume changed %d \n " , avrcp_subevent_notification_volume_changed_get_absolute_volume ( packet ) ) ;
return ;
case AVRCP_SUBEVENT_NOTIFICATION_AVAILABLE_PLAYERS_CHANGED :
printf ( " notification changed \n " ) ;
return ;
case AVRCP_SUBEVENT_SHUFFLE_AND_REPEAT_MODE : {
uint8_t shuffle_mode = avrcp_subevent_shuffle_and_repeat_mode_get_shuffle_mode ( packet ) ;
uint8_t repeat_mode = avrcp_subevent_shuffle_and_repeat_mode_get_repeat_mode ( packet ) ;
printf ( " %s, %s \n " , avrcp_shuffle2str ( shuffle_mode ) , avrcp_repeat2str ( repeat_mode ) ) ;
break ;
}
case AVRCP_SUBEVENT_NOW_PLAYING_INFO : {
uint8_t value [ 100 ] ;
printf ( " now playing: \n " ) ;
if ( avrcp_subevent_now_playing_info_get_title_len ( packet ) > 0 ) {
memcpy ( value , avrcp_subevent_now_playing_info_get_title ( packet ) , avrcp_subevent_now_playing_info_get_title_len ( packet ) ) ;
printf ( " Title: %s \n " , value ) ;
}
if ( avrcp_subevent_now_playing_info_get_album_len ( packet ) > 0 ) {
memcpy ( value , avrcp_subevent_now_playing_info_get_album ( packet ) , avrcp_subevent_now_playing_info_get_album_len ( packet ) ) ;
printf ( " Album: %s \n " , value ) ;
}
if ( avrcp_subevent_now_playing_info_get_artist_len ( packet ) > 0 ) {
memcpy ( value , avrcp_subevent_now_playing_info_get_artist ( packet ) , avrcp_subevent_now_playing_info_get_artist_len ( packet ) ) ;
printf ( " Artist: %s \n " , value ) ;
}
if ( avrcp_subevent_now_playing_info_get_genre_len ( packet ) > 0 ) {
memcpy ( value , avrcp_subevent_now_playing_info_get_genre ( packet ) , avrcp_subevent_now_playing_info_get_genre_len ( packet ) ) ;
printf ( " Genre: %s \n " , value ) ;
}
printf ( " Track: %d \n " , avrcp_subevent_now_playing_info_get_track ( packet ) ) ;
printf ( " Total nr. tracks: %d \n " , avrcp_subevent_now_playing_info_get_total_tracks ( packet ) ) ;
printf ( " Song length: %d ms \n " , avrcp_subevent_now_playing_info_get_song_length ( packet ) ) ;
break ;
}
case AVRCP_SUBEVENT_PLAY_STATUS :
printf ( " song length: %d ms, song position: %d ms, play status: %s \n " ,
avrcp_subevent_play_status_get_song_length ( packet ) ,
avrcp_subevent_play_status_get_song_position ( packet ) ,
avrcp_play_status2str ( avrcp_subevent_play_status_get_play_status ( packet ) ) ) ;
break ;
case AVRCP_SUBEVENT_OPERATION_COMPLETE :
printf ( " operation done %s \n " , avrcp_operation2str ( avrcp_subevent_operation_complete_get_operation_id ( packet ) ) ) ;
break ;
case AVRCP_SUBEVENT_OPERATION_START :
printf ( " operation start %s \n " , avrcp_operation2str ( avrcp_subevent_operation_complete_get_operation_id ( packet ) ) ) ;
break ;
case AVRCP_SUBEVENT_PLAYER_APPLICATION_VALUE_RESPONSE :
// response to set shuffle and repeat mode
printf ( " \n " ) ;
break ;
default :
printf ( " AVRCP event not parsed. \n " ) ;
break ;
}
break ;
2017-06-14 14:32:51 +02:00
default :
break ;
}
}
# ifdef HAVE_BTSTACK_STDIN
static void show_usage ( void ) {
bd_addr_t iut_address ;
gap_local_bd_addr ( iut_address ) ;
printf ( " \n --- Bluetooth AVDTP Sink/AVRCP Connection Test Console %s --- \n " , bd_addr_to_str ( iut_address ) ) ;
printf ( " b - AVDTP Sink create connection to addr %s \n " , device_addr_string ) ;
printf ( " B - AVDTP Sink disconnect \n " ) ;
printf ( " c - AVRCP create connection to addr %s \n " , device_addr_string ) ;
printf ( " C - AVRCP disconnect \n " ) ;
printf ( " \n --- Bluetooth AVRCP Commands %s --- \n " , bd_addr_to_str ( iut_address ) ) ;
2017-06-14 15:50:50 +02:00
printf ( " q - get capabilities: supported events \n " ) ;
printf ( " w - get unit info \n " ) ;
printf ( " r - get play status \n " ) ;
printf ( " t - get now playing info \n " ) ;
printf ( " 1 - play \n " ) ;
printf ( " 2 - stop \n " ) ;
printf ( " 3 - pause \n " ) ;
printf ( " 4 - fast forward \n " ) ;
printf ( " 5 - rewind \n " ) ;
printf ( " 6 - forward \n " ) ;
printf ( " 7 - backward \n " ) ;
printf ( " 8 - volume up \n " ) ;
printf ( " 9 - volume down \n " ) ;
printf ( " 0 - mute \n " ) ;
printf ( " R - absolute volume of 50 percent \n " ) ;
printf ( " u - skip \n " ) ;
printf ( " i - query repeat and shuffle mode \n " ) ;
printf ( " o - repeat single track \n " ) ;
printf ( " x/X - repeat/disable repeat all tracks \n " ) ;
printf ( " z/Z - shuffle/disable shuffle all tracks \n " ) ;
printf ( " a/A - register/deregister PLAYBACK_STATUS_CHANGED \n " ) ;
printf ( " s/S - register/deregister TRACK_CHANGED \n " ) ;
printf ( " d/D - register/deregister TRACK_REACHED_END \n " ) ;
printf ( " f/F - register/deregister TRACK_REACHED_START \n " ) ;
printf ( " g/G - register/deregister PLAYBACK_POS_CHANGED \n " ) ;
printf ( " h/H - register/deregister BATT_STATUS_CHANGED \n " ) ;
printf ( " j/J - register/deregister SYSTEM_STATUS_CHANGED \n " ) ;
printf ( " k/K - register/deregister PLAYER_APPLICATION_SETTING_CHANGED \n " ) ;
printf ( " l/L - register/deregister NOW_PLAYING_CONTENT_CHANGED \n " ) ;
printf ( " m/M - register/deregister AVAILABLE_PLAYERS_CHANGED \n " ) ;
printf ( " n/N - register/deregister ADDRESSED_PLAYER_CHANGED \n " ) ;
printf ( " y/Y - register/deregister UIDS_CHANGED \n " ) ;
printf ( " v/V - register/deregister VOLUME_CHANGED \n " ) ;
2017-06-14 14:32:51 +02:00
printf ( " Ctrl-c - exit \n " ) ;
printf ( " --- \n " ) ;
}
# endif
static uint8_t media_sbc_codec_capabilities [ ] = {
0xFF , //(AVDTP_SBC_44100 << 4) | AVDTP_SBC_STEREO,
0xFF , //(AVDTP_SBC_BLOCK_LENGTH_16 << 4) | (AVDTP_SBC_SUBBANDS_8 << 2) | AVDTP_SBC_ALLOCATION_METHOD_LOUDNESS,
2 , 53
} ;
# ifdef HAVE_BTSTACK_STDIN
static void stdin_process ( char cmd ) {
sep . seid = 1 ;
switch ( cmd ) {
case ' b ' :
2017-07-13 14:35:07 +02:00
printf ( " Establish AVDTP sink connection to %s \n " , device_addr_string ) ;
2017-07-12 16:35:01 +02:00
avdtp_sink_connect ( device_addr , & avdtp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' B ' :
2017-07-13 14:35:07 +02:00
printf ( " Disconnect AVDTP sink \n " ) ;
2017-06-14 14:32:51 +02:00
avdtp_sink_disconnect ( avdtp_cid ) ;
break ;
case ' c ' :
2017-07-13 14:35:07 +02:00
printf ( " Establish AVRCP connection to %s. \n " , bd_addr_to_str ( device_addr ) ) ;
2017-07-12 22:53:41 +02:00
avrcp_controller_connect ( device_addr , & avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' C ' :
2017-07-13 14:35:07 +02:00
printf ( " Disconnect AVRCP \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disconnect ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' \n ' :
case ' \r ' :
break ;
2017-06-14 15:50:50 +02:00
case ' q ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: get capabilities: supported events \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_get_supported_events ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' w ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: get unit info \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_unit_info ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' r ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: get play status \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_get_play_status ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' t ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: get now playing info \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_get_now_playing_info ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 1 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: play \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_play ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 2 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: stop \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_stop ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 3 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: pause \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_pause ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 4 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: fast forward \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_fast_forward ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 5 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: rewind \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_rewind ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 6 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: forward \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_forward ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 7 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: backward \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_backward ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 8 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: volume up \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_volume_up ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 9 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: volume down \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_volume_down ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' 0 ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: mute \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_mute ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' R ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: absolute volume of 50 percent \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_absolute_volume ( avrcp_cid , 50 ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' u ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: skip \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_skip ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' i ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: query repeat and shuffle mode \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_query_shuffle_and_repeat_modes ( avrcp_cid ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' o ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: repeat single track \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_repeat_mode ( avrcp_cid , AVRCP_REPEAT_MODE_SINGLE_TRACK ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' x ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: repeat all tracks \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_repeat_mode ( avrcp_cid , AVRCP_REPEAT_MODE_ALL_TRACKS ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' X ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable repeat mode \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_repeat_mode ( avrcp_cid , AVRCP_REPEAT_MODE_OFF ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' z ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: shuffle all tracks \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_shuffle_mode ( avrcp_cid , AVRCP_SHUFFLE_MODE_ALL_TRACKS ) ;
2017-06-14 14:32:51 +02:00
break ;
case ' Z ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable shuffle mode \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_set_shuffle_mode ( avrcp_cid , AVRCP_SHUFFLE_MODE_OFF ) ;
2017-06-14 14:32:51 +02:00
break ;
2017-06-14 15:50:50 +02:00
case ' a ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification PLAYBACK_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' s ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification TRACK_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' d ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification TRACK_REACHED_END \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' f ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification TRACK_REACHED_START \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' g ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification PLAYBACK_POS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' h ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification BATT_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' j ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification SYSTEM_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' k ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification PLAYER_APPLICATION_SETTING_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' l ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification NOW_PLAYING_CONTENT_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' m ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification AVAILABLE_PLAYERS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' n ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification ADDRESSED_PLAYER_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' y ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification UIDS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' v ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: enable notification VOLUME_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_enable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' A ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification PLAYBACK_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYBACK_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' S ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification TRACK_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' D ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification TRACK_REACHED_END \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_END ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' F ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification TRACK_REACHED_START \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_TRACK_REACHED_START ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' G ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification PLAYBACK_POS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYBACK_POS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' H ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification BATT_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_BATT_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' J ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification SYSTEM_STATUS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_SYSTEM_STATUS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' K ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification PLAYER_APPLICATION_SETTING_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_PLAYER_APPLICATION_SETTING_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' L ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification NOW_PLAYING_CONTENT_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_NOW_PLAYING_CONTENT_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' M ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification AVAILABLE_PLAYERS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_AVAILABLE_PLAYERS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' N ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification ADDRESSED_PLAYER_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_ADDRESSED_PLAYER_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' Y ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification UIDS_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_UIDS_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
case ' V ' :
2017-07-13 14:35:07 +02:00
printf ( " AVRCP: disable notification VOLUME_CHANGED \n " ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_disable_notification ( avrcp_cid , AVRCP_NOTIFICATION_EVENT_VOLUME_CHANGED ) ;
2017-06-14 15:50:50 +02:00
break ;
2017-06-14 14:32:51 +02:00
default :
show_usage ( ) ;
break ;
}
}
# endif
int btstack_main ( int argc , const char * argv [ ] ) ;
int btstack_main ( int argc , const char * argv [ ] ) {
UNUSED ( argc ) ;
( void ) argv ;
/* Register for HCI events */
hci_event_callback_registration . callback = & packet_handler ;
hci_add_event_handler ( & hci_event_callback_registration ) ;
l2cap_init ( ) ;
// Initialize AVDTP Sink
2017-07-12 16:35:01 +02:00
avdtp_sink_init ( & a2dp_sink_context ) ;
2017-06-14 14:32:51 +02:00
avdtp_sink_register_packet_handler ( & packet_handler ) ;
local_stream_endpoint = avdtp_sink_create_stream_endpoint ( AVDTP_SINK , AVDTP_AUDIO ) ;
local_stream_endpoint - > sep . seid = 1 ;
avdtp_sink_register_media_transport_category ( local_stream_endpoint - > sep . seid ) ;
avdtp_sink_register_media_codec_category ( local_stream_endpoint - > sep . seid , AVDTP_AUDIO , AVDTP_CODEC_SBC , media_sbc_codec_capabilities , sizeof ( media_sbc_codec_capabilities ) ) ;
// Initialize AVRCP COntroller
2017-07-12 16:35:01 +02:00
avrcp_controller_init ( ) ;
2017-07-21 11:55:25 +02:00
avrcp_controller_register_packet_handler ( & packet_handler ) ;
2017-06-14 14:32:51 +02:00
// Initialize SDP
sdp_init ( ) ;
// setup AVDTP sink
memset ( sdp_avdtp_sink_service_buffer , 0 , sizeof ( sdp_avdtp_sink_service_buffer ) ) ;
a2dp_sink_create_sdp_record ( sdp_avdtp_sink_service_buffer , 0x10001 , 1 , NULL , NULL ) ;
sdp_register_service ( sdp_avdtp_sink_service_buffer ) ;
// setup AVRCP
memset ( sdp_avrcp_controller_service_buffer , 0 , sizeof ( sdp_avrcp_controller_service_buffer ) ) ;
avrcp_controller_create_sdp_record ( sdp_avrcp_controller_service_buffer , 0x10001 , AVRCP_BROWSING_ENABLED , 1 , NULL , NULL ) ;
sdp_register_service ( sdp_avrcp_controller_service_buffer ) ;
2017-07-13 16:04:55 +02:00
gap_set_local_name ( " BTstack AVRCP PTS Test " ) ;
2017-06-14 14:32:51 +02:00
gap_discoverable_control ( 1 ) ;
gap_set_class_of_device ( 0x200408 ) ;
# ifdef HAVE_BTSTACK_STDIN
// parse human readable Bluetooth address
sscanf_bd_addr ( device_addr_string , device_addr ) ;
btstack_stdin_setup ( stdin_process ) ;
# endif
2017-07-12 16:35:01 +02:00
// turn on!
hci_power_control ( HCI_POWER_ON ) ;
2017-06-14 14:32:51 +02:00
return 0 ;
}