avdtp_acceptor.c (5cfe7f4cc81075ececf34a61639f3bc15baacb2c) | avdtp_acceptor.c (6484b28a8cf2e8dc89acafacb3c57e97937a4b51) |
---|---|
1/* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 186 unchanged lines hidden (view full) --- 195 case AVDTP_SI_GET_CAPABILITIES: 196 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES\n"); 197 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES; 198 break; 199 case AVDTP_SI_SET_CONFIGURATION:{ 200 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION \n"); 201 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION; 202 connection->reject_service_category = 0; | 1/* 2 * Copyright (C) 2016 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright --- 186 unchanged lines hidden (view full) --- 195 case AVDTP_SI_GET_CAPABILITIES: 196 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES\n"); 197 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CAPABILITIES; 198 break; 199 case AVDTP_SI_SET_CONFIGURATION:{ 200 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION \n"); 201 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION; 202 connection->reject_service_category = 0; |
203 stream_endpoint->connection = connection; | 203 |
204 avdtp_sep_t sep; 205 sep.seid = connection->signaling_packet.command[offset++] >> 2; 206 sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+offset, packet_size-offset); 207 sep.in_use = 1; 208 209 if (connection->error_code){ 210 printf("fire configuration parsing errors \n"); 211 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 212 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 213 break; 214 } 215 // find or add sep | 204 avdtp_sep_t sep; 205 sep.seid = connection->signaling_packet.command[offset++] >> 2; 206 sep.configured_service_categories = avdtp_unpack_service_capabilities(connection, &sep.configuration, connection->signaling_packet.command+offset, packet_size-offset); 207 sep.in_use = 1; 208 209 if (connection->error_code){ 210 printf("fire configuration parsing errors \n"); 211 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 212 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 213 break; 214 } 215 // find or add sep |
216 stream_endpoint->remote_sep_index = avdtp_find_remote_sep(stream_endpoint->connection, sep.seid); | 216 int i; 217 stream_endpoint->remote_sep_index = AVDTP_INVALID_SEP_INDEX; 218 for (i=0; i < stream_endpoint->remote_seps_num; i++){ 219 if (stream_endpoint->remote_seps[i].seid == sep.seid){ 220 stream_endpoint->remote_sep_index = i; 221 } 222 } |
217 printf(" ACP .. seid %d, index %d\n", sep.seid, stream_endpoint->remote_sep_index); 218 | 223 printf(" ACP .. seid %d, index %d\n", sep.seid, stream_endpoint->remote_sep_index); 224 |
219 if (stream_endpoint->remote_sep_index != 0xFF){ 220 if (stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].in_use){ | 225 if (stream_endpoint->remote_sep_index != AVDTP_INVALID_SEP_INDEX){ 226 if (stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].in_use){ |
221 // reject if already configured 222 connection->error_code = SEP_IN_USE; 223 // find first registered category and fire the error 224 connection->reject_service_category = 0; | 227 // reject if already configured 228 connection->error_code = SEP_IN_USE; 229 // find first registered category and fire the error 230 connection->reject_service_category = 0; |
225 int i; | |
226 for (i = 1; i < 9; i++){ 227 if (get_bit16(sep.configured_service_categories, i)){ 228 connection->reject_service_category = i; 229 break; 230 } 231 } 232 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 233 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 234 } else { | 231 for (i = 1; i < 9; i++){ 232 if (get_bit16(sep.configured_service_categories, i)){ 233 connection->reject_service_category = i; 234 break; 235 } 236 } 237 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 238 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 239 } else { |
235 stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; 236 printf(" ACP: update seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); | 240 stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; 241 printf(" ACP: update seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); |
237 } 238 } else { 239 // add new 240 printf(" ACP: seid %d not found in %p\n", sep.seid, stream_endpoint); | 242 } 243 } else { 244 // add new 245 printf(" ACP: seid %d not found in %p\n", sep.seid, stream_endpoint); |
241 stream_endpoint->remote_sep_index = connection->remote_seps_num; 242 connection->remote_seps_num++; 243 connection->remote_seps[stream_endpoint->remote_sep_index] = sep; 244 printf(" ACP: add seid %d, to %p\n", connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); | 246 stream_endpoint->remote_sep_index = stream_endpoint->remote_seps_num; 247 stream_endpoint->remote_seps_num++; 248 stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; 249 printf(" ACP: add seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); |
245 } | 250 } |
251 |
|
246 if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ 247 switch (sep.configuration.media_codec.media_codec_type){ 248 case AVDTP_CODEC_SBC: | 252 if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ 253 switch (sep.configuration.media_codec.media_codec_type){ 254 case AVDTP_CODEC_SBC: |
249 avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->acp_seid, sep.configuration.media_codec); | 255 avdtp_signaling_emit_media_codec_sbc_configuration(context->avdtp_callback, connection->con_handle, sep.configuration.media_codec); |
250 break; 251 default: | 256 break; 257 default: |
252 avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->acp_seid, sep.configuration.media_codec); | 258 avdtp_signaling_emit_media_codec_other_configuration(context->avdtp_callback, connection->con_handle, sep.configuration.media_codec); |
253 break; 254 } 255 } | 259 break; 260 } 261 } |
256 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->signaling_packet.signal_identifier, 0); | 262 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->signaling_packet.signal_identifier, 0); |
257 break; 258 } 259 case AVDTP_SI_RECONFIGURE:{ 260 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE; 261 connection->reject_service_category = 0; 262 263 avdtp_sep_t sep; 264 sep.seid = connection->query_seid; --- 5 unchanged lines hidden (view full) --- 270 if (connection->error_code){ 271 // fire configuration parsing errors 272 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 273 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 274 break; 275 } 276 277 // find sep or raise error | 263 break; 264 } 265 case AVDTP_SI_RECONFIGURE:{ 266 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE; 267 connection->reject_service_category = 0; 268 269 avdtp_sep_t sep; 270 sep.seid = connection->query_seid; --- 5 unchanged lines hidden (view full) --- 276 if (connection->error_code){ 277 // fire configuration parsing errors 278 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 279 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 280 break; 281 } 282 283 // find sep or raise error |
278 stream_endpoint->remote_sep_index = avdtp_find_remote_sep(stream_endpoint->connection, sep.seid); 279 if (stream_endpoint->remote_sep_index == 0xFF){ | 284 int i; 285 stream_endpoint->remote_sep_index = AVDTP_INVALID_SEP_INDEX; 286 for (i = 0; i < stream_endpoint->remote_seps_num; i++){ 287 if (stream_endpoint->remote_seps[i].seid == sep.seid){ 288 stream_endpoint->remote_sep_index = i; 289 } 290 } 291 292 if (stream_endpoint->remote_sep_index == AVDTP_INVALID_SEP_INDEX){ |
280 printf(" ACP: REJECT AVDTP_SI_RECONFIGURE, BAD_ACP_SEID\n"); 281 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 282 connection->error_code = BAD_ACP_SEID; 283 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 284 break; 285 } | 293 printf(" ACP: REJECT AVDTP_SI_RECONFIGURE, BAD_ACP_SEID\n"); 294 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_REJECT_CATEGORY_WITH_ERROR_CODE; 295 connection->error_code = BAD_ACP_SEID; 296 connection->reject_signal_identifier = connection->signaling_packet.signal_identifier; 297 break; 298 } |
286 stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index] = sep; 287 printf(" ACP: update seid %d, to %p\n", stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); | 299 stream_endpoint->remote_seps[stream_endpoint->remote_sep_index] = sep; 300 printf(" ACP: update seid %d, to %p\n", stream_endpoint->remote_seps[stream_endpoint->remote_sep_index].seid, stream_endpoint); |
288 289 if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ 290 switch (sep.capabilities.media_codec.media_codec_type){ 291 case AVDTP_CODEC_SBC: | 301 302 if (get_bit16(sep.configured_service_categories, AVDTP_MEDIA_CODEC)){ 303 switch (sep.capabilities.media_codec.media_codec_type){ 304 case AVDTP_CODEC_SBC: |
292 avdtp_signaling_emit_media_codec_sbc_reconfiguration(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->acp_seid, sep.capabilities.media_codec); | 305 avdtp_signaling_emit_media_codec_sbc_reconfiguration(context->avdtp_callback, connection->con_handle, sep.capabilities.media_codec); |
293 break; 294 default: | 306 break; 307 default: |
295 avdtp_signaling_emit_media_codec_other_reconfiguration(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->acp_seid, sep.capabilities.media_codec); | 308 avdtp_signaling_emit_media_codec_other_reconfiguration(context->avdtp_callback, connection->con_handle, sep.capabilities.media_codec); |
296 break; 297 } 298 } | 309 break; 310 } 311 } |
299 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->signaling_packet.signal_identifier, 0); | 312 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->signaling_packet.signal_identifier, 0); |
300 break; 301 } 302 303 case AVDTP_SI_GET_CONFIGURATION: 304 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION\n"); 305 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION; 306 break; 307 case AVDTP_SI_OPEN: --- 215 unchanged lines hidden (view full) --- 523 } 524 l2cap_send_prepared(cid, pos); 525 break; 526 case AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION: 527 printf(" ACP: DONE\n"); 528 printf(" -> AVDTP_STREAM_ENDPOINT_CONFIGURED\n"); 529 stream_endpoint->connection = connection; 530 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; | 313 break; 314 } 315 316 case AVDTP_SI_GET_CONFIGURATION: 317 printf(" ACP: AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION\n"); 318 stream_endpoint->acceptor_config_state = AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION; 319 break; 320 case AVDTP_SI_OPEN: --- 215 unchanged lines hidden (view full) --- 536 } 537 l2cap_send_prepared(cid, pos); 538 break; 539 case AVDTP_ACCEPTOR_W2_ANSWER_SET_CONFIGURATION: 540 printf(" ACP: DONE\n"); 541 printf(" -> AVDTP_STREAM_ENDPOINT_CONFIGURED\n"); 542 stream_endpoint->connection = connection; 543 stream_endpoint->state = AVDTP_STREAM_ENDPOINT_CONFIGURED; |
544 // TODO: use actual config |
|
531 // TODO: consider reconfiguration | 545 // TODO: consider reconfiguration |
546 btstack_sbc_encoder_init(&stream_endpoint->sbc_encoder_state, SBC_MODE_STANDARD, 16, 8, 2, 44100, 53); 547 |
|
532 avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_SET_CONFIGURATION); 533 break; 534 case AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE: 535 printf(" ACP: DONE \n"); 536 avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_RECONFIGURE); 537 break; 538 539 case AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION:{ | 548 avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_SET_CONFIGURATION); 549 break; 550 case AVDTP_ACCEPTOR_W2_ANSWER_RECONFIGURE: 551 printf(" ACP: DONE \n"); 552 avdtp_acceptor_send_accept_response(cid, trid, AVDTP_SI_RECONFIGURE); 553 break; 554 555 case AVDTP_ACCEPTOR_W2_ANSWER_GET_CONFIGURATION:{ |
540 avdtp_sep_t sep = stream_endpoint->connection->remote_seps[stream_endpoint->remote_sep_index]; | 556 avdtp_sep_t sep = stream_endpoint->remote_seps[stream_endpoint->remote_sep_index]; |
541 avdtp_prepare_capabilities(&connection->signaling_packet, trid, sep.configured_service_categories, sep.configuration, AVDTP_SI_GET_CONFIGURATION); 542 l2cap_reserve_packet_buffer(); 543 out_buffer = l2cap_get_outgoing_buffer(); 544 pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer); 545 if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){ 546 stream_endpoint->acceptor_config_state = acceptor_config_state; 547 printf(" ACP: fragmented\n"); 548 } else { --- 45 unchanged lines hidden (view full) --- 594 connection->error_code = 0; 595 avdtp_acceptor_send_response_reject_with_error_code(cid, reject_signal_identifier, error_code, trid); 596 break; 597 default: 598 status = 0; 599 printf(" ACP: NOT IMPLEMENTED\n"); 600 sent = 0; 601 } | 557 avdtp_prepare_capabilities(&connection->signaling_packet, trid, sep.configured_service_categories, sep.configuration, AVDTP_SI_GET_CONFIGURATION); 558 l2cap_reserve_packet_buffer(); 559 out_buffer = l2cap_get_outgoing_buffer(); 560 pos = avdtp_signaling_create_fragment(cid, &connection->signaling_packet, out_buffer); 561 if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){ 562 stream_endpoint->acceptor_config_state = acceptor_config_state; 563 printf(" ACP: fragmented\n"); 564 } else { --- 45 unchanged lines hidden (view full) --- 610 connection->error_code = 0; 611 avdtp_acceptor_send_response_reject_with_error_code(cid, reject_signal_identifier, error_code, trid); 612 break; 613 default: 614 status = 0; 615 printf(" ACP: NOT IMPLEMENTED\n"); 616 sent = 0; 617 } |
602 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->int_seid, connection->signaling_packet.signal_identifier, status); | 618 avdtp_signaling_emit_accept(context->avdtp_callback, connection->con_handle, connection->signaling_packet.signal_identifier, status); |
603 604 // check fragmentation 605 if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){ 606 avdtp_request_can_send_now_acceptor(connection, connection->l2cap_signaling_cid); 607 } 608} | 619 620 // check fragmentation 621 if (connection->signaling_packet.packet_type != AVDTP_SINGLE_PACKET && connection->signaling_packet.packet_type != AVDTP_END_PACKET){ 622 avdtp_request_can_send_now_acceptor(connection, connection->l2cap_signaling_cid); 623 } 624} |