2021-12-06 01:59:55 -05:00
|
|
|
|
/*
|
2024-05-01 08:26:15 -04:00
|
|
|
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
2021-12-06 01:59:55 -05:00
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
|
|
|
|
*/
|
2019-04-03 08:11:17 -04:00
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
2022-12-07 22:03:04 -05:00
|
|
|
|
#include <inttypes.h>
|
2019-04-03 08:11:17 -04:00
|
|
|
|
#include "esp_log.h"
|
|
|
|
|
#include "ble_ancs.h"
|
|
|
|
|
|
|
|
|
|
#define BLE_ANCS_TAG "BLE_ANCS"
|
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
|
/*
|
2019-04-03 08:11:17 -04:00
|
|
|
|
| EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) |
|
|
|
|
|
|
|
|
|
|
A GATT notification delivered through the Notification Source characteristic contains the following information:
|
|
|
|
|
* EventID: This field informs the accessory whether the given iOS notification was added, modified, or removed. The enumerated values for this field are defined
|
|
|
|
|
in EventID Values.
|
|
|
|
|
* EventFlags: A bitmask whose set bits inform an NC of specificities with the iOS notification. For example, if an iOS notification is considered “important”,
|
|
|
|
|
the NC may want to display a more aggressive user interface (UI) to make sure the user is properly alerted. The enumerated bits for this field
|
|
|
|
|
are defined in EventFlags.
|
2020-11-10 02:40:01 -05:00
|
|
|
|
* CategoryID: A numerical value providing a category in which the iOS notification can be classified. The NP will make a best effort to provide an accurate category
|
2019-04-03 08:11:17 -04:00
|
|
|
|
for each iOS notification. The enumerated values for this field are defined in CategoryID Values.
|
|
|
|
|
* CategoryCount: The current number of active iOS notifications in the given category. For example, if two unread emails are sitting in a user’s email inbox, and a new
|
|
|
|
|
email is pushed to the user’s iOS device, the value of CategoryCount is 3.
|
|
|
|
|
* NotificationUID: A 32-bit numerical value that is the unique identifier (UID) for the iOS notification. This value can be used as a handle in commands sent to the
|
|
|
|
|
Control Point characteristic to interact with the iOS notification.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
char *EventID_to_String(uint8_t EventID)
|
|
|
|
|
{
|
|
|
|
|
char *str = NULL;
|
|
|
|
|
switch (EventID)
|
|
|
|
|
{
|
|
|
|
|
case EventIDNotificationAdded:
|
|
|
|
|
str = "New message";
|
|
|
|
|
break;
|
|
|
|
|
case EventIDNotificationModified:
|
|
|
|
|
str = "Modified message";
|
|
|
|
|
break;
|
|
|
|
|
case EventIDNotificationRemoved:
|
|
|
|
|
str = "Removed message";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
str = "unknown EventID";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *CategoryID_to_String(uint8_t CategoryID)
|
|
|
|
|
{
|
|
|
|
|
char *Cidstr = NULL;
|
|
|
|
|
switch(CategoryID) {
|
|
|
|
|
case CategoryIDOther:
|
|
|
|
|
Cidstr = "Other";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDIncomingCall:
|
|
|
|
|
Cidstr = "IncomingCall";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDMissedCall:
|
|
|
|
|
Cidstr = "MissedCall";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDVoicemail:
|
|
|
|
|
Cidstr = "Voicemail";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDSocial:
|
|
|
|
|
Cidstr = "Social";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDSchedule:
|
|
|
|
|
Cidstr = "Schedule";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDEmail:
|
|
|
|
|
Cidstr = "Email";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDNews:
|
|
|
|
|
Cidstr = "News";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDHealthAndFitness:
|
|
|
|
|
Cidstr = "HealthAndFitness";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDBusinessAndFinance:
|
|
|
|
|
Cidstr = "BusinessAndFinance";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDLocation:
|
|
|
|
|
Cidstr = "Location";
|
|
|
|
|
break;
|
|
|
|
|
case CategoryIDEntertainment:
|
|
|
|
|
Cidstr = "Entertainment";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Cidstr = "Unknown CategoryID";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return Cidstr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
|
/*
|
2019-04-03 08:11:17 -04:00
|
|
|
|
| EventID(1 Byte) | EventFlags(1 Byte) | CategoryID(1 Byte) | CategoryCount(1 Byte) | NotificationUID(4 Bytes) |
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void esp_receive_apple_notification_source(uint8_t *message, uint16_t message_len)
|
|
|
|
|
{
|
|
|
|
|
if (!message || message_len < 5) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t EventID = message[0];
|
|
|
|
|
char *EventIDS = EventID_to_String(EventID);
|
|
|
|
|
uint8_t EventFlags = message[1];
|
|
|
|
|
uint8_t CategoryID = message[2];
|
|
|
|
|
char *Cidstr = CategoryID_to_String(CategoryID);
|
|
|
|
|
uint8_t CategoryCount = message[3];
|
|
|
|
|
uint32_t NotificationUID = (message[4]) | (message[5]<< 8) | (message[6]<< 16) | (message[7] << 24);
|
2022-12-07 22:03:04 -05:00
|
|
|
|
ESP_LOGI(BLE_ANCS_TAG, "EventID:%s EventFlags:0x%x CategoryID:%s CategoryCount:%d NotificationUID:%" PRIu32, EventIDS, EventFlags, Cidstr, CategoryCount, NotificationUID);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
|
void esp_receive_apple_data_source(uint8_t *message, uint16_t message_len)
|
2019-04-03 08:11:17 -04:00
|
|
|
|
{
|
|
|
|
|
if (!message || message_len == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
uint8_t Command_id = message[0];
|
|
|
|
|
switch (Command_id)
|
|
|
|
|
{
|
|
|
|
|
case CommandIDGetNotificationAttributes: {
|
|
|
|
|
uint32_t NotificationUID = (message[1]) | (message[2]<< 8) | (message[3]<< 16) | (message[4] << 24);
|
|
|
|
|
uint32_t remian_attr_len = message_len - 5;
|
|
|
|
|
uint8_t *attrs = &message[5];
|
2022-12-07 22:03:04 -05:00
|
|
|
|
ESP_LOGI(BLE_ANCS_TAG, "recevice Notification Attributes response Command_id %d NotificationUID %" PRIu32, Command_id, NotificationUID);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
while(remian_attr_len > 0) {
|
|
|
|
|
uint8_t AttributeID = attrs[0];
|
|
|
|
|
uint16_t len = attrs[1] | (attrs[2] << 8);
|
|
|
|
|
if(len > (remian_attr_len -3)) {
|
|
|
|
|
ESP_LOGE(BLE_ANCS_TAG, "data error");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
switch (AttributeID)
|
|
|
|
|
{
|
|
|
|
|
case NotificationAttributeIDAppIdentifier:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("Identifier", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDTitle:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("Title", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDSubtitle:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("Subtitle", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDMessage:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("Message", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDMessageSize:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("MessageSize", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDDate:
|
|
|
|
|
//yyyyMMdd'T'HHmmSS
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_CHAR("Date", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDPositiveActionLabel:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_HEX("PActionLabel", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
case NotificationAttributeIDNegativeActionLabel:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_HEX("NActionLabel", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2024-05-01 08:26:15 -04:00
|
|
|
|
ESP_LOG_BUFFER_HEX("unknownAttributeID", &attrs[3], len);
|
2019-04-03 08:11:17 -04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrs += (1 + 2 + len);
|
|
|
|
|
remian_attr_len -= (1 + 2 + len);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case CommandIDGetAppAttributes:
|
|
|
|
|
ESP_LOGI(BLE_ANCS_TAG, "recevice APP Attributes response");
|
|
|
|
|
break;
|
|
|
|
|
case CommandIDPerformNotificationAction:
|
|
|
|
|
ESP_LOGI(BLE_ANCS_TAG, "recevice Perform Notification Action");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
ESP_LOGI(BLE_ANCS_TAG, "unknown Command ID");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 02:40:01 -05:00
|
|
|
|
char *Errcode_to_String(uint16_t status)
|
2019-04-03 08:11:17 -04:00
|
|
|
|
{
|
|
|
|
|
char *Errstr = NULL;
|
|
|
|
|
switch (status) {
|
|
|
|
|
case Unknown_command:
|
|
|
|
|
Errstr = "Unknown_command";
|
|
|
|
|
break;
|
|
|
|
|
case Invalid_command:
|
|
|
|
|
Errstr = "Invalid_command";
|
|
|
|
|
break;
|
|
|
|
|
case Invalid_parameter:
|
|
|
|
|
Errstr = "Invalid_parameter";
|
|
|
|
|
break;
|
|
|
|
|
case Action_failed:
|
|
|
|
|
Errstr = "Action_failed";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Errstr = "unknown_failed";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return Errstr;
|
|
|
|
|
|
|
|
|
|
}
|