mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
map_client: enable/disable notification
This commit is contained in:
parent
88954725a2
commit
3eb02ce6c7
@ -114,6 +114,9 @@ typedef uint8_t sm_key_t[16];
|
||||
// AVRCP browsing data
|
||||
#define AVRCP_BROWSING_DATA_PACKET 0x0f
|
||||
|
||||
// MAP data
|
||||
#define MAP_DATA_PACKET 0x10
|
||||
|
||||
|
||||
// debug log messages
|
||||
#define LOG_MESSAGE_PACKET 0xfc
|
||||
|
@ -87,6 +87,8 @@ typedef enum {
|
||||
MAP_W4_MESSAGES_IN_FOLDER,
|
||||
MAP_W2_SEND_GET_MESSAGE_WITH_HANDLE,
|
||||
MAP_W4_MESSAGE,
|
||||
MAP_W2_SET_NOTIFICATION,
|
||||
MAP_W4_SET_NOTIFICATION,
|
||||
|
||||
MAP_W2_SEND_DISCONNECT_REQUEST,
|
||||
MAP_W4_DISCONNECT_RESPONSE,
|
||||
@ -104,12 +106,12 @@ typedef struct map_client {
|
||||
const char * folder_name;
|
||||
const char * current_folder;
|
||||
uint16_t set_path_offset;
|
||||
uint8_t notifications_enabled;
|
||||
|
||||
map_message_handle_t message_handle;
|
||||
uint8_t get_message_attachment;
|
||||
} map_client_t;
|
||||
|
||||
|
||||
static map_client_t _map_client;
|
||||
static map_client_t * map_client = &_map_client;
|
||||
|
||||
@ -273,6 +275,20 @@ static void map_handle_can_send_now(void){
|
||||
map_client->state = MAP_W4_MESSAGE;
|
||||
goep_client_execute(map_client->goep_cid);
|
||||
break;
|
||||
|
||||
case MAP_W2_SET_NOTIFICATION:
|
||||
goep_client_create_put_request(map_client->goep_cid);
|
||||
goep_client_add_header_type(map_client->goep_cid, "x-bt/MAP-NotificationRegistration");
|
||||
|
||||
application_parameters[pos++] = 0x0E; // NotificationStatus
|
||||
application_parameters[pos++] = 1;
|
||||
application_parameters[pos++] = map_client->notifications_enabled;
|
||||
|
||||
goep_client_add_header_application_parameters(map_client->goep_cid, pos, &application_parameters[0]);
|
||||
goep_client_add_body_static(map_client->goep_cid, 1, (uint8_t *) "0");
|
||||
map_client->state = MAP_W4_MESSAGE;
|
||||
goep_client_execute(map_client->goep_cid);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -459,4 +475,22 @@ uint8_t map_client_set_path(uint16_t map_cid, char * path){
|
||||
map_client->set_path_offset = 0;
|
||||
goep_client_request_can_send_now(map_client->goep_cid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t map_client_enable_notifications(uint16_t map_cid){
|
||||
UNUSED(map_cid);
|
||||
if (map_client->state != MAP_CONNECTED) return BTSTACK_BUSY;
|
||||
map_client->state = MAP_W2_SET_NOTIFICATION;
|
||||
map_client->notifications_enabled = 1;
|
||||
goep_client_request_can_send_now(map_client->goep_cid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t map_client_disable_notifications(uint16_t map_cid){
|
||||
UNUSED(map_cid);
|
||||
if (map_client->state != MAP_CONNECTED) return BTSTACK_BUSY;
|
||||
map_client->state = MAP_W2_SET_NOTIFICATION;
|
||||
map_client->notifications_enabled = 0;
|
||||
goep_client_request_can_send_now(map_client->goep_cid);
|
||||
return 0;
|
||||
}
|
@ -100,6 +100,20 @@ uint8_t map_client_get_message_listing_for_folder(uint16_t map_cid, const char *
|
||||
*/
|
||||
uint8_t map_client_get_message_with_handle(uint16_t map_cid, const map_message_handle_t map_message_handle, uint8_t with_attachment);
|
||||
|
||||
/**
|
||||
* @brief Enable notifications.
|
||||
* @param map_cid
|
||||
* @return status
|
||||
*/
|
||||
uint8_t map_client_enable_notifications(uint16_t map_cid);
|
||||
|
||||
/**
|
||||
* @brief Disable notifications.
|
||||
* @param map_cid
|
||||
* @return status
|
||||
*/
|
||||
uint8_t map_client_disable_notifications(uint16_t map_cid);
|
||||
|
||||
/* API_END */
|
||||
|
||||
#if defined __cplusplus
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "l2cap.h"
|
||||
#include "classic/rfcomm.h"
|
||||
#include "btstack_event.h"
|
||||
#include "bluetooth_sdp.h"
|
||||
#include "classic/goep_client.h"
|
||||
#include "map_client.h"
|
||||
#include "map_server.h"
|
||||
@ -72,6 +73,7 @@
|
||||
static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static bd_addr_t remote_addr;
|
||||
static uint16_t rfcomm_channel_id;
|
||||
// MBP2016 "F4-0F-24-3B-1B-E1"
|
||||
// Nexus 7 "30-85-A9-54-2E-78"
|
||||
// iPhone SE "BC:EC:5D:E6:15:03"
|
||||
@ -100,7 +102,9 @@ static void show_usage(void){
|
||||
printf("p - set path \'%s\'\n", path);
|
||||
printf("f - get folder listing\n");
|
||||
printf("F - get message listing for folder \'%s\'\n", folder_name);
|
||||
printf("l - get message for last found handle'\n");
|
||||
printf("l - get message for last found handle\n");
|
||||
printf("n - enable notifications\n");
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@ -131,7 +135,10 @@ static void stdin_process(char c){
|
||||
printf("[+] Get message for hardcoded handle\n");
|
||||
map_client_get_message_with_handle(map_cid, message_handle, 1);
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
printf("[+] Enable notifications\n");
|
||||
map_client_enable_notifications(map_cid);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
break;
|
||||
@ -144,7 +151,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
UNUSED(size);
|
||||
int i;
|
||||
uint8_t status;
|
||||
// char buffer[32];
|
||||
uint16_t mtu;
|
||||
|
||||
switch (packet_type){
|
||||
case HCI_EVENT_PACKET:
|
||||
switch (hci_event_packet_get_type(packet)) {
|
||||
@ -154,6 +162,29 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
show_usage();
|
||||
}
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_INCOMING_CONNECTION:
|
||||
rfcomm_channel_id = rfcomm_event_incoming_connection_get_rfcomm_cid(packet);
|
||||
printf("RFCOMM connection opened\n");
|
||||
rfcomm_accept_connection(rfcomm_channel_id);
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_OPENED:
|
||||
// data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
if (rfcomm_event_channel_opened_get_status(packet)) {
|
||||
printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet));
|
||||
} else {
|
||||
rfcomm_channel_id = rfcomm_event_channel_opened_get_rfcomm_cid(packet);
|
||||
mtu = rfcomm_event_channel_opened_get_max_frame_size(packet);
|
||||
printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_channel_id, mtu);
|
||||
}
|
||||
break;
|
||||
|
||||
case RFCOMM_EVENT_CHANNEL_CLOSED:
|
||||
printf("RFCOMM channel closed\n");
|
||||
rfcomm_channel_id = 0;
|
||||
break;
|
||||
|
||||
case HCI_EVENT_MAP_META:
|
||||
switch (hci_event_map_meta_get_subevent_code(packet)){
|
||||
case MAP_SUBEVENT_CONNECTION_OPENED:
|
||||
@ -179,10 +210,20 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RFCOMM_DATA_PACKET:
|
||||
printf("RFCOMM data packet: '");
|
||||
for (i=0;i<size;i++){
|
||||
printf("%02x ", packet[i]);
|
||||
}
|
||||
printf("'\n");
|
||||
break;
|
||||
|
||||
case MAP_DATA_PACKET:
|
||||
for (i=0;i<size;i++){
|
||||
printf("%c", packet[i]);
|
||||
}
|
||||
printf("\n");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -190,7 +231,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint8_t map_message_service_service_buffer[150];
|
||||
static uint8_t map_message_notification_service_buffer[150];
|
||||
const char * name = "MAP Service";
|
||||
|
||||
int btstack_main(int argc, const char * argv[]);
|
||||
@ -218,10 +259,14 @@ int btstack_main(int argc, const char * argv[]){
|
||||
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);
|
||||
int rfcomm_channel_nr = 1;
|
||||
|
||||
memset(map_message_notification_service_buffer, 0, sizeof(map_message_notification_service_buffer));
|
||||
map_message_notification_service_create_sdp_record(map_message_notification_service_buffer, 0x10001,
|
||||
1, rfcomm_channel_nr, 1, supported_message_types, supported_features, name);
|
||||
sdp_register_service(map_message_notification_service_buffer);
|
||||
|
||||
rfcomm_register_service(&packet_handler, rfcomm_channel_nr, 0xFFFF);
|
||||
// register for HCI events
|
||||
hci_event_callback_registration.callback = &packet_handler;
|
||||
hci_add_event_handler(&hci_event_callback_registration);
|
||||
|
Loading…
x
Reference in New Issue
Block a user