diff --git a/test/map_client/Makefile b/test/map_client/Makefile index 70dee4ca0..ea1aab387 100644 --- a/test/map_client/Makefile +++ b/test/map_client/Makefile @@ -29,7 +29,7 @@ LDFLAGS += $(shell pkg-config libusb-1.0 --libs) all: map_client_test -map_client_test: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} md5.o obex_iterator.o goep_client.o yxml.o map_client.o map_client_test.c +map_client_test: ${CORE_OBJ} ${COMMON_OBJ} ${CLASSIC_OBJ} ${SDP_CLIENT} ${SDP_SERVER} md5.o obex_iterator.o goep_client.o yxml.o map_client.o map_server.o map_client_test.c ${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@ diff --git a/test/map_client/map.h b/test/map_client/map.h new file mode 100644 index 000000000..5b20a1e00 --- /dev/null +++ b/test/map_client/map.h @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2019 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 + * + */ + +#ifndef __MAP_H +#define __MAP_H + +#if defined __cplusplus +extern "C" { +#endif + +#include "btstack_config.h" +#include + +/* API_START */ + +#define MAP_MESSAGE_HANDLE_SIZE 8 +/** + * @brief MAP Message handle + */ +typedef uint8_t map_message_handle_t[MAP_MESSAGE_HANDLE_SIZE]; + +typedef enum { + MAP_MESSAGE_TYPE_EMAIL = 0, + MAP_MESSAGE_TYPE_SMS_GSM, + MAP_MESSAGE_TYPE_SMS_CDMA, + MAP_MESSAGE_TYPE_MMS, + MAP_MESSAGE_TYPE_IM +} map_message_type_t; + +typedef enum { + MAP_FEATURE_NOTIFICATION_REGISTRATION = 0, + MAP_FEATURE_NOTIFICATION, + MAP_FEATURE_BROWSING, + MAP_FEATURE_UPLOADING, + MAP_FEATURE_DELETE, + MAP_FEATURE_INSTANCE_INFORMATION, + MAP_FEATURE_EXTENDED_EVENT_REPORT_1_1, + MAP_FEATURE_EVENT_REPORT_VERSION_1_2, + MAP_FEATURE_MESSAGE_FORMAT_VERSION_1_1, + MAP_FEATURE_MESSAGES_LISTING_FORMAT_VERSION_1_1, + MAP_FEATURE_PERSISTENT_MESSAGE_HANDLES, + MAP_FEATURE_DATABASE_IDENTIFIER, + MAP_FEATURE_FOLDER_VERSION_COUNTER, + MAP_FEATURE_CONVERSATION_VERSION_COUNTERS, + MAP_FEATURE_PARTICIPANT_PRESENCE_CHANGE_NOTIFICATION, + MAP_FEATURE_PARTICIPANT_CHAT_STATE_CHANGE_NOTIFICATION, + MAP_FEATURE_PBAP_CONTACT_CROSS_REFERENCE, + MAP_FEATURE_NOTIFICATION_FILTERING, + MAP_FEATURE_UTC_OFFSET_TIMESTAMP_FORMAT, + MAP_FEATURE_MAPSUPPORTEDFEATURES_IN_CONNECT_REQUEST, + MAP_FEATURE_CONVERSATION_LISTING, + MAP_FEATURE_OWNER_STATUS_BIT, + MAP_FEATURE_MESSAGE_FORWARDING +} map_feature_t; + +/* API_END */ + +#if defined __cplusplus +} +#endif +#endif diff --git a/test/map_client/map_client.c b/test/map_client/map_client.c index cd0778c9f..cd6200069 100644 --- a/test/map_client/map_client.c +++ b/test/map_client/map_client.c @@ -54,6 +54,8 @@ #include "bluetooth_sdp.h" #include "classic/sdp_client_rfcomm.h" #include "btstack_event.h" +#include "classic/sdp_client.h" +#include "classic/sdp_util.h" #include "classic/obex.h" #include "classic/obex_iterator.h" @@ -107,6 +109,7 @@ typedef struct map_client { uint8_t get_message_attachment; } map_client_t; + static map_client_t _map_client; static map_client_t * map_client = &_map_client; diff --git a/test/map_client/map_client.h b/test/map_client/map_client.h index 5459eb4c2..204473b45 100644 --- a/test/map_client/map_client.h +++ b/test/map_client/map_client.h @@ -36,22 +36,18 @@ */ #ifndef __MAP_CLIENT_H +#define __MAP_CLIENT_H #if defined __cplusplus extern "C" { #endif #include "btstack_config.h" +#include "map.h" #include /* API_START */ -#define MAP_MESSAGE_HANDLE_SIZE 8 -/** - * @brief MAP Message handle - */ -typedef uint8_t map_message_handle_t[MAP_MESSAGE_HANDLE_SIZE]; - /** * */ diff --git a/test/map_client/map_client_test.c b/test/map_client/map_client_test.c index 42480a071..d284c508d 100644 --- a/test/map_client/map_client_test.c +++ b/test/map_client/map_client_test.c @@ -60,6 +60,10 @@ #include "btstack_event.h" #include "classic/goep_client.h" #include "map_client.h" +#include "map_server.h" +#include "classic/sdp_client.h" +#include "classic/sdp_util.h" +#include "classic/sdp_server.h" #ifdef HAVE_BTSTACK_STDIN #include "btstack_stdin.h" @@ -186,6 +190,9 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe } #endif +static uint8_t map_message_service_service_buffer[150]; +const char * name = "MAP Service"; + int btstack_main(int argc, const char * argv[]); int btstack_main(int argc, const char * argv[]){ @@ -201,8 +208,19 @@ int btstack_main(int argc, const char * argv[]){ // init GOEP Client goep_client_init(); - // init PBAP Client + // init MAP Client map_client_init(); + // init MAP Server + map_server_init(); + + sdp_init(); + // setup AVDTP sink + map_message_type_t supported_message_types = MAP_MESSAGE_TYPE_SMS_GSM; + map_feature_t supported_features = 0x1F; + + memset(map_message_service_service_buffer, 0, sizeof(map_message_service_service_buffer)); + map_access_service_create_sdp_record(map_message_service_service_buffer, 0x10001, 1, 1, 1, 1, supported_message_types, supported_features, name); + sdp_register_service(map_message_service_service_buffer); // register for HCI events hci_event_callback_registration.callback = &packet_handler; diff --git a/test/map_client/map_server.c b/test/map_client/map_server.c new file mode 100644 index 000000000..ed86a5753 --- /dev/null +++ b/test/map_client/map_server.c @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2019 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 + * + */ + +#define __BTSTACK_FILE__ "map_server.c" + +#include "btstack_config.h" + +#include +#include +#include +#include + +#include "hci_cmd.h" +#include "btstack_run_loop.h" +#include "btstack_debug.h" +#include "hci.h" +#include "btstack_memory.h" +#include "hci_dump.h" +#include "l2cap.h" +#include "bluetooth_sdp.h" +#include "classic/sdp_client_rfcomm.h" +#include "btstack_event.h" +#include "classic/sdp_client.h" +#include "classic/sdp_util.h" + +#include "classic/obex.h" +#include "classic/obex_iterator.h" +#include "classic/goep_client.h" +#include "map_server.h" + +#define MAP_MAX_NUM_ENTRIES 1024 + +// map access service bb582b40-420c-11db-b0de-0800200c9a66 + +typedef enum { + MAP_INIT = 0, + MAP_CONNECTED +} map_state_t; + +typedef struct map_server { + map_state_t state; + uint16_t cid; + bd_addr_t bd_addr; + hci_con_handle_t con_handle; + uint16_t goep_cid; +} map_server_t; + + +static map_server_t _map_server; +static map_server_t * map_server = &_map_server; + +void map_access_service_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, uint8_t instance_id, + int rfcomm_channel_nr, uint16_t goep_l2cap_psm, map_message_type_t supported_message_types, map_feature_t supported_features, const char * name){ + uint8_t* attribute; + de_create_sequence(service); + + // 0x0000 "Service Record Handle" + de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE); + de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle); + + // 0x0001 "Service Class ID List" + de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST); + attribute = de_push_sequence(service); + { + // "UUID for Service" + de_add_number(attribute, DE_UUID, DE_SIZE_16, service_uuid); + de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_MESSAGE_ACCESS_SERVER); + } + de_pop_sequence(service, attribute); + + // 0x0004 "Protocol Descriptor List" + de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST); + attribute = de_push_sequence(service); + { + uint8_t* l2cpProtocol = de_push_sequence(attribute); + { + de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP); + } + de_pop_sequence(attribute, l2cpProtocol); + + uint8_t* rfcomm = de_push_sequence(attribute); + { + de_add_number(rfcomm, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_RFCOMM); // rfcomm_service + de_add_number(rfcomm, DE_UINT, DE_SIZE_8, rfcomm_channel_nr); // rfcomm channel + } + de_pop_sequence(attribute, rfcomm); + + uint8_t* obexProtocol = de_push_sequence(attribute); + { + de_add_number(obexProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_OBEX); + } + de_pop_sequence(attribute, obexProtocol); + + } + de_pop_sequence(service, attribute); + + + // 0x0005 "Public Browse Group" + de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BROWSE_GROUP_LIST); // public browse group + attribute = de_push_sequence(service); + { + de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PUBLIC_BROWSE_ROOT); + } + de_pop_sequence(service, attribute); + + // 0x0009 "Bluetooth Profile Descriptor List" + de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST); + attribute = de_push_sequence(service); + { + uint8_t *sppProfile = de_push_sequence(attribute); + { + de_add_number(sppProfile, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_MESSAGE_ACCESS_PROFILE); + de_add_number(sppProfile, DE_UINT, DE_SIZE_16, 0x0103); // Verision 1.7 + } + de_pop_sequence(attribute, sppProfile); + } + de_pop_sequence(service, attribute); + + // "Service Name" + de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100); + de_add_data(service, DE_STRING, strlen(name), (uint8_t *) name); + +#ifdef ENABLE_GOEP_L2CAP + // 0x0200 "GoepL2CapPsm" + de_add_number(service, DE_UINT, DE_SIZE_16, 0x0200); + de_add_number(service, DE_UINT, DE_SIZE_16, goep_l2cap_psm); +#endif + + // 0x0315 "MASInstanceID" + de_add_number(service, DE_UINT, DE_SIZE_16, 0x0315); + de_add_number(service, DE_UINT, DE_SIZE_8, instance_id); + + // 0x0316 "SupportedMessageTypes" + de_add_number(service, DE_UINT, DE_SIZE_16, 0x0316); + de_add_number(service, DE_UINT, DE_SIZE_8, supported_message_types); + + // 0x0317 "MapSupportedFeatures" + de_add_number(service, DE_UINT, DE_SIZE_16, 0x0317); + de_add_number(service, DE_UINT, DE_SIZE_32, supported_features); +} + + +static void map_handle_can_send_now(void){ +} + +static void map_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ + UNUSED(channel); + UNUSED(size); + // printf("packet_type 0x%02x, event type 0x%02x, subevent 0x%02x\n", packet_type, hci_event_packet_get_type(packet), hci_event_goep_meta_get_subevent_code(packet)); +} + +void map_server_init(void){ + memset(map_server, 0, sizeof(map_server_t)); + map_server->state = MAP_INIT; + map_server->cid = 1; +} diff --git a/test/map_client/map_server.h b/test/map_client/map_server.h new file mode 100644 index 000000000..b3620db0a --- /dev/null +++ b/test/map_client/map_server.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2019 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 + * + */ + +#ifndef __MAP_SERVER_H +#define __MAP_SERVER_H + +#if defined __cplusplus +extern "C" { +#endif + +#include "btstack_config.h" +#include +#include "map.h" + +/* API_START */ + +/** + * + */ +void map_access_service_create_sdp_record(uint8_t * service, uint32_t service_record_handle, uint16_t service_uuid, uint8_t instance_id, + int rfcomm_channel_nr, uint16_t goep_l2cap_psm, map_message_type_t supported_message_types, map_feature_t supported_features, const char * name); + +/** + * + */ +void map_server_init(void); + +/* API_END */ + +#if defined __cplusplus +} +#endif +#endif