att_server.c (40f8d8f21f6e40da7dc986a8b1f082cc8fba9f10) att_server.c (d74c7b2b8daffb43a10c469d3962bcf8dd014bcb)
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

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

1341 att_server_request_can_send_now(att_server, att_connection);
1342 if (added){
1343 return ERROR_CODE_SUCCESS;
1344 } else {
1345 return ERROR_CODE_COMMAND_DISALLOWED;
1346 }
1347}
1348
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

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

1341 att_server_request_can_send_now(att_server, att_connection);
1342 if (added){
1343 return ERROR_CODE_SUCCESS;
1344 } else {
1345 return ERROR_CODE_COMMAND_DISALLOWED;
1346 }
1347}
1348
1349static uint8_t att_server_prepare_server_message(hci_con_handle_t con_handle, att_server_t ** out_att_server, att_connection_t ** out_att_connection, uint8_t ** out_packet_buffer){
1350
1351 att_server_t * att_server = NULL;
1352 att_connection_t * att_connection = NULL;
1353 uint8_t * packet_buffer = NULL;
1354
1355 // prefer enhanced bearer
1356#ifdef ENABLE_GATT_OVER_EATT
1357 att_server_eatt_bearer_t * eatt_bearer = att_server_eatt_bearer_for_con_handle(con_handle);
1358 if (eatt_bearer != NULL){
1359 att_server = &eatt_bearer->att_server;
1360 att_connection = &eatt_bearer->att_connection;
1361 packet_buffer = eatt_bearer->send_buffer;
1362 } else
1363#endif
1364 {
1365 hci_connection_t *hci_connection = hci_connection_for_handle(con_handle);
1366 if (hci_connection != NULL) {
1367 att_server = &hci_connection->att_server;
1368 att_connection = &hci_connection->att_connection;
1369 }
1370 }
1371
1372 if (att_server == NULL) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1373 if (!att_server_can_send_packet(att_server, att_connection)) return BTSTACK_ACL_BUFFERS_FULL;
1374
1375 if (packet_buffer == NULL){
1376 l2cap_reserve_packet_buffer();
1377 packet_buffer = l2cap_get_outgoing_buffer();
1378 }
1379
1380 *out_att_connection = att_connection;
1381 *out_att_server = att_server;
1382 *out_packet_buffer = packet_buffer;
1383 return ERROR_CODE_SUCCESS;
1384}
1385
1349uint8_t att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
1350 hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);
1351 if (!hci_connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1352 att_server_t * att_server = &hci_connection->att_server;
1353 att_connection_t * att_connection = &hci_connection->att_connection;
1354
1355 if (!att_server_can_send_packet(att_server, att_connection)) return BTSTACK_ACL_BUFFERS_FULL;
1356

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

1372 */
1373uint8_t att_server_multiple_notify(hci_con_handle_t con_handle, uint8_t num_attributes,
1374 const uint16_t * attribute_handles, const uint8_t ** values_data, const uint16_t * values_len){
1375
1376 att_server_t * att_server = NULL;
1377 att_connection_t * att_connection = NULL;
1378 uint8_t * packet_buffer = NULL;
1379
1386uint8_t att_server_notify(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
1387 hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);
1388 if (!hci_connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1389 att_server_t * att_server = &hci_connection->att_server;
1390 att_connection_t * att_connection = &hci_connection->att_connection;
1391
1392 if (!att_server_can_send_packet(att_server, att_connection)) return BTSTACK_ACL_BUFFERS_FULL;
1393

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

1409 */
1410uint8_t att_server_multiple_notify(hci_con_handle_t con_handle, uint8_t num_attributes,
1411 const uint16_t * attribute_handles, const uint8_t ** values_data, const uint16_t * values_len){
1412
1413 att_server_t * att_server = NULL;
1414 att_connection_t * att_connection = NULL;
1415 uint8_t * packet_buffer = NULL;
1416
1380 // prfer enhanced bearer
1381#ifdef ENABLE_GATT_OVER_EATT
1382 att_server_eatt_bearer_t * eatt_bearer = att_server_eatt_bearer_for_con_handle(con_handle);
1383 if (eatt_bearer != NULL){
1384 att_server = &eatt_bearer->att_server;
1385 att_connection = &eatt_bearer->att_connection;
1386 packet_buffer = eatt_bearer->send_buffer;
1387 } else
1388#endif
1389 {
1390 hci_connection_t *hci_connection = hci_connection_for_handle(con_handle);
1391 if (hci_connection != NULL) {
1392 att_server = &hci_connection->att_server;
1393 att_connection = &hci_connection->att_connection;
1394 }
1417 uint8_t status = att_server_prepare_server_message(con_handle, &att_server, &att_connection, &packet_buffer);
1418 if (status != ERROR_CODE_SUCCESS){
1419 return status;
1395 }
1396
1420 }
1421
1397 if (att_server == NULL) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;
1398 if (!att_server_can_send_packet(att_server, att_connection)) return BTSTACK_ACL_BUFFERS_FULL;
1399
1400 if (packet_buffer == NULL){
1401 l2cap_reserve_packet_buffer();
1402 packet_buffer = l2cap_get_outgoing_buffer();
1403 }
1404
1405 uint16_t size = att_prepare_handle_value_multiple_notification(att_connection, num_attributes, attribute_handles, values_data, values_len, packet_buffer);
1406
1407 return att_server_send_prepared(att_server, att_connection, packet_buffer, size);
1408}
1409
1410uint8_t att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
1411 hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);
1412 if (!hci_connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;

--- 203 unchanged lines hidden ---
1422 uint16_t size = att_prepare_handle_value_multiple_notification(att_connection, num_attributes, attribute_handles, values_data, values_len, packet_buffer);
1423
1424 return att_server_send_prepared(att_server, att_connection, packet_buffer, size);
1425}
1426
1427uint8_t att_server_indicate(hci_con_handle_t con_handle, uint16_t attribute_handle, const uint8_t *value, uint16_t value_len){
1428 hci_connection_t * hci_connection = hci_connection_for_handle(con_handle);
1429 if (!hci_connection) return ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER;

--- 203 unchanged lines hidden ---