att_server.c (e7af4f1f3fbacefcfce6ef51ec9a88ab3110367d) att_server.c (c5867c46b4f5d643d5d0c311df0b602f7e392b8c)
1/*
2 * Copyright (C) 2014 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

--- 542 unchanged lines hidden (view full) ---

551 // update sequence number
552 uint32_t counter_packet = little_endian_read_32(att_server->request_buffer, att_server->request_size-12);
553 le_device_db_remote_counter_set(att_server->ir_le_device_db_index, counter_packet+1);
554 att_server->state = ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED;
555 att_server_request_can_send_now(att_server, att_connection);
556}
557#endif
558
1/*
2 * Copyright (C) 2014 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

--- 542 unchanged lines hidden (view full) ---

551 // update sequence number
552 uint32_t counter_packet = little_endian_read_32(att_server->request_buffer, att_server->request_size-12);
553 le_device_db_remote_counter_set(att_server->ir_le_device_db_index, counter_packet+1);
554 att_server->state = ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED;
555 att_server_request_can_send_now(att_server, att_connection);
556}
557#endif
558
559#ifdef ENABLE_ATT_DELAYED_RESPONSE
560static void att_server_handle_response_pending(att_server_t *att_server, const att_connection_t *att_connection,
561 const uint8_t *eatt_buffer,
562 uint16_t att_response_size) {
563 // free reserved buffer
564 if (eatt_buffer == NULL){
565 l2cap_release_packet_buffer();
566 }
567
568 // update state
569 att_server->state = ATT_SERVER_RESPONSE_PENDING;
570
571 // callback with handle ATT_READ_RESPONSE_PENDING for reads
572 if (att_response_size == ATT_READ_RESPONSE_PENDING){
573 // notify services that returned response pending
574 btstack_linked_list_iterator_t it;
575 btstack_linked_list_iterator_init(&it, &service_handlers);
576 while (btstack_linked_list_iterator_has_next(&it)) {
577 att_service_handler_t *handler = (att_service_handler_t *) btstack_linked_list_iterator_next(&it);
578 if ((handler->flags & ATT_SERVICE_FLAGS_DELAYED_RESPONSE) != 0){
579 handler->flags &= ~ATT_SERVICE_FLAGS_DELAYED_RESPONSE;
580 handler->read_callback(att_connection->con_handle, ATT_READ_RESPONSE_PENDING, 0, NULL, 0);
581 }
582 }
583 // notify main read callback if it returned response pending
584 if ((att_server_flags & ATT_SERVICE_FLAGS_DELAYED_RESPONSE) != 0){
585 // flag was set by read callback
586 btstack_assert(att_server_client_read_callback != NULL);
587 (*att_server_client_read_callback)(att_connection->con_handle, ATT_READ_RESPONSE_PENDING, 0, NULL, 0);
588 }
589 }
590}
591#endif
592
559// pre: att_server->state == ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED
560// pre: can send now
561// uses l2cap outgoing buffer if no eatt_buffer provided
562// returns: 1 if packet was sent
563static int
564att_server_process_validated_request(att_server_t *att_server, att_connection_t *att_connection, uint8_t *eatt_buffer) {
565
566 uint8_t * att_response_buffer;

--- 14 unchanged lines hidden (view full) ---

581 att_response_buffer[3] = 0;
582 att_response_buffer[4] = ATT_ERROR_REQUEST_NOT_SUPPORTED;
583 } else {
584 att_response_size = att_handle_request(att_connection, att_server->request_buffer, att_server->request_size, att_response_buffer);
585 }
586
587#ifdef ENABLE_ATT_DELAYED_RESPONSE
588 if ((att_response_size == ATT_READ_RESPONSE_PENDING) || (att_response_size == ATT_INTERNAL_WRITE_RESPONSE_PENDING)){
593// pre: att_server->state == ATT_SERVER_REQUEST_RECEIVED_AND_VALIDATED
594// pre: can send now
595// uses l2cap outgoing buffer if no eatt_buffer provided
596// returns: 1 if packet was sent
597static int
598att_server_process_validated_request(att_server_t *att_server, att_connection_t *att_connection, uint8_t *eatt_buffer) {
599
600 uint8_t * att_response_buffer;

--- 14 unchanged lines hidden (view full) ---

615 att_response_buffer[3] = 0;
616 att_response_buffer[4] = ATT_ERROR_REQUEST_NOT_SUPPORTED;
617 } else {
618 att_response_size = att_handle_request(att_connection, att_server->request_buffer, att_server->request_size, att_response_buffer);
619 }
620
621#ifdef ENABLE_ATT_DELAYED_RESPONSE
622 if ((att_response_size == ATT_READ_RESPONSE_PENDING) || (att_response_size == ATT_INTERNAL_WRITE_RESPONSE_PENDING)){
589 // free reserved buffer
590 if (eatt_buffer == NULL){
591 l2cap_release_packet_buffer();
592 }
593
594 // update state
595 att_server->state = ATT_SERVER_RESPONSE_PENDING;
596
597 // callback with handle ATT_READ_RESPONSE_PENDING for reads
598 if (att_response_size == ATT_READ_RESPONSE_PENDING){
599 // notify services that returned response pending
600 btstack_linked_list_iterator_t it;
601 btstack_linked_list_iterator_init(&it, &service_handlers);
602 while (btstack_linked_list_iterator_has_next(&it)) {
603 att_service_handler_t *handler = (att_service_handler_t *) btstack_linked_list_iterator_next(&it);
604 if ((handler->flags & ATT_SERVICE_FLAGS_DELAYED_RESPONSE) != 0){
605 handler->flags &= ~ATT_SERVICE_FLAGS_DELAYED_RESPONSE;
606 handler->read_callback(att_connection->con_handle, ATT_READ_RESPONSE_PENDING, 0, NULL, 0);
607 }
608 }
609 // notify main read callback if it returned response pending
610 if ((att_server_flags & ATT_SERVICE_FLAGS_DELAYED_RESPONSE) != 0){
611 // flag was set by read callback
612 btstack_assert(att_server_client_read_callback != NULL);
613 (*att_server_client_read_callback)(att_connection->con_handle, ATT_READ_RESPONSE_PENDING, 0, NULL, 0);
614 }
615 }
623 att_server_handle_response_pending(att_server, att_connection, eatt_buffer, att_response_size);
616 return 0;
617 }
618#endif
619
620 // intercept "insufficient authorization" for authenticated connections to allow for user authorization
621 if ((att_response_size >= 4u)
622 && (att_response_buffer[0] == ATT_ERROR_RESPONSE)
623 && (att_response_buffer[4] == ATT_ERROR_INSUFFICIENT_AUTHORIZATION)

--- 1059 unchanged lines hidden ---
624 return 0;
625 }
626#endif
627
628 // intercept "insufficient authorization" for authenticated connections to allow for user authorization
629 if ((att_response_size >= 4u)
630 && (att_response_buffer[0] == ATT_ERROR_RESPONSE)
631 && (att_response_buffer[4] == ATT_ERROR_INSUFFICIENT_AUTHORIZATION)

--- 1059 unchanged lines hidden ---