+
+ int offset = 0;
+ int uuid_len = 4;
+ typedef struct {
+ const char *uuid;
+ const char *specification_name;
+ } uuid_name_s;
+ static uuid_name_s short_uuid_name[SHORT_UUID_COUNT] = {
+ // List should be sorted by UUID
+ /* BT Classic Services */
+ {"1101", "Serial Port Service"},
+ {"1102", "LAN Access Using PPP Service"},
+ {"1103", "Dialup Networking Service"},
+ {"1104", "IrMCSync Service"},
+ {"1105", "OBEX Object Push Service"},
+ {"1106", "OBEX File Transfer Service"},
+ {"1107", "IrMC Sync Command Service"},
+ {"1108", "Headset Service"},
+ {"1109", "Cordless Telephony Service"},
+ {"110A", "Audio Source Service"},
+ {"110B", "Audio Sink Service"},
+ {"110C", "AV Remote Control Target Service"},
+ {"110D", "Advanced Audio Distribution Profile"},
+ {"110E", "AV Remote Control Service"},
+ {"110F", "Video Conferencing Service"},
+ {"1110", "Intercom Service"},
+ {"1111", "Fax Service"},
+ {"1112", "Headset Audio Gateway Service"},
+ {"1113", "WAP Service"},
+ {"1114", "WAP Client Service"},
+ {"1115", "PANU Service"},
+ {"1116", "NAP Service"},
+ {"1117", "GN Service"},
+ {"1118", "Direct Printing Service"},
+ {"1119", "Reference Printing Service"},
+ {"111A", "Basic Imaging Profile"},
+ {"111B", "Imaging Responder Service"},
+ {"111C", "Imaging Automatic Archive Service"},
+ {"111D", "Imaging Reference Objects Service"},
+ {"111E", "Handsfree Service"},
+ {"111F", "Handsfree Audio Gateway Service"},
+ {"1120", "Direct Printing Reference Objects Service"},
+ {"1121", "Reflected UI Service"},
+ {"1122", "Basic Printing Profile"},
+ {"1123", "Printing Status Service"},
+ {"1124", "Human Interface Device Service"},
+ {"1125", "Hardcopy Cable Replacement Profile"},
+ {"1126", "HCR Print Service"},
+ {"1127", "HCR Scan Service"},
+ {"112D", "SIM Access Service"},
+ {"112E", "Phonebook Access PCE Service"},
+ {"112F", "Phonebook Access PSE Service"},
+ {"1130", "Phonebook Access Profile"},
+ {"1132", "Message Access Server Service"},
+ {"1133", "Message Notification Server Service"},
+ {"1134", "Message Access Profile"},
+ {"1200", "PnP Information Service"},
+ {"1201", "Generic Networking Service"},
+ {"1202", "Generic File Transfer Service"},
+ {"1203", "Generic Audio Service"},
+ {"1204", "Generic Telephony Service"},
+ {"1205", "UPnP Service"},
+ {"1206", "UPnP Ip Service"},
+ {"1303", "Video Source Service"},
+ {"1304", "Video Sink Service"},
+ {"1305", "Video Distribution Profile"},
+ {"1400", "Health Device Profile"},
+ {"1401", "HDP Source Service"},
+ {"1402", "HDP Sink Service"},
+
+ /* GATT Services */
+ {"1800", "Generic Access"},
+ {"1801", "Generic Attribute"},
+ {"1802", "Immediate Alert"},
+ {"1803", "Link Loss"},
+ {"1804", "Tx Power"},
+ {"1805", "Current Time Service"},
+ {"1806", "Reference Time Update Service"},
+ {"1807", "Next DST Change Service"},
+ {"1808", "Glucose"},
+ {"1809", "Health Thermometer"},
+ {"180A", "Device Information"},
+ {"180D", "Heart Rate"},
+ {"180F", "Battery Service"},
+ {"1810", "Blood Pressure"},
+ {"1811", "Alert Notification Service"},
+ {"1812", "Human Interface Device"},
+ {"1813", "Scan Parameters"},
+ {"1814", "Running Speed and Cadence"},
+ {"1815", "Automation IO"},
+ {"1816", "Cycling Speed and Cadence"},
+ {"1818", "Cycling Power"},
+ {"1819", "Location and Navigation"},
+ {"181A", "Environmental Sensing"},
+ {"181B", "Body Composition"},
+ {"181C", "User Data"},
+ {"181D", "Weight Scale"},
+ {"181E", "Bond Management"},
+ {"181F", "Continuous Glucose Monitoring"},
+ {"1820", "Internet Protocol Support Service"},
+ {"1821", "Indoor Positioning"},
+ {"1822", "Pulse Oximeter Service"},
+ {"1823", "HTTP Proxy"},
+ {"1824", "Transport Discovery"},
+ {"1825", "Object Transfer Service"},
+ {"1826", "Fitness Machine"},
+ {"1827", "Mesh Provisioning Service"},
+ {"1828", "Mesh Proxy Service"},
+ {"1829", "Reconnection Configuration"},
+ {"183A", "Insulin Delivery"},
+
+ /* GATT Declarations */
+ {"2800", "Primary Service Declaration"},
+ {"2801", "Secondary Service Declaration"},
+ {"2802", "Include Declaration"},
+ {"2803", "Characteristic Declaration"},
+
+ /* GATT Descriptors */
+ {"2900", "Characteristic Extended Properties"},
+ {"2901", "Characteristic User Description"},
+ {"2902", "Client Characteristic Configuration"},
+ {"2903", "Server Characteristic Configuration"},
+ {"2904", "Characteristic Format"},
+ {"2905", "Characteristic Aggregate Formate"},
+ {"2906", "Valid Range"},
+ {"2907", "External Report Reference"},
+ {"2908", "Report Reference"},
+
+ /* GATT Characteristics */
+ {"2A00", "Device Name"},
+ {"2A01", "Appearance"},
+ {"2A02", "Peripheral Privacy Flag"},
+ {"2A03", "Reconnection Address"},
+ {"2A04", "Peripheral Preferred Connection Parameters"},
+ {"2A05", "Service Changed"},
+ {"2A06", "Alert Level"},
+ {"2A07", "Tx Power Level"},
+ {"2A08", "Date Time"},
+ {"2A09", "Day of Week"},
+ {"2A0A", "Day Date Time"},
+ {"2A11", "Time with DST"},
+ {"2A12", "Time Accuracy"},
+ {"2A13", "Time Source"},
+ {"2A14", "Reference Time Information"},
+ {"2A16", "Time Update Control Point"},
+ {"2A17", "Time Update State"},
+ {"2A18", "Glucose Measurement"},
+ {"2A19", "Battery Level"},
+ {"2A1C", "Temperature Measurement"},
+ {"2A1D", "Temperature Type"},
+ {"2A1E", "Intermediate Temperature"},
+ {"2A21", "Measurement Interval"},
+ {"2A23", "System ID"},
+ {"2A24", "Model Number String"},
+ {"2A25", "Serial Number String"},
+ {"2A26", "Firmware Revision String"},
+ {"2A27", "Hardware Revision String"},
+ {"2A28", "Software Revision String"},
+ {"2A29", "Manufacturer Name String"},
+ {"2A2A", "IEEE 11073-20601 Regulatory Certification Data List"},
+ {"2A2B", "Current Time"},
+ {"2A34", "Glucose Measurement Context"},
+ {"2A35", "Blood Pressure Measurement"},
+ {"2A37", "Heart Rate Measurement"},
+ {"2A38", "Body Sensor Location"},
+ {"2A39", "Heart Rate Control Point"},
+ {"2A3F", "Alert Status"},
+ {"2A46", "New Alert"},
+ {"2A49", "Blood Pressure Feature"},
+ {"2A4A", "HID Information"},
+ {"2A4C", "HID Control Point"},
+ {"2A50", "PnP ID"},
+ {"2A51", "Glucose Feature"},
+ {"2A52", "Record Access Control Point"},
+ {"2A53", "RSC Measurement"},
+ {"2A54", "RSC Feature"},
+ {"2A55", "SC Control Point"},
+ {"2A56", "Digital"},
+ {"2A58", "Analog"},
+ {"2A5A", "Aggregate"},
+ {"2A5B", "CSC Measurement"},
+ {"2A5C", "CSC Feature"},
+ {"2A5D", "Sensor Location"},
+ {"2A63", "Cycling Power Measurement"},
+ {"2A64", "Cycling Power Vector"},
+ {"2A65", "Cycling Power Feature"},
+ {"2A66", "Cycling Power Control Point"},
+ {"2A67", "Location and Speed"},
+ {"2A68", "Navigation"},
+ {"2A6D", "Pressure"},
+ {"2A6E", "Temperature"},
+ {"2A8E", "Height"},
+ {"2A90", "Last Name"},
+ {"2A91", "Maximum Recommended Heart Rate"},
+ {"2A92", "Resting Heart Rate"},
+ {"2A98", "Weight"},
+ {"2A9B", "Body Composition Feature"},
+ {"2A9C", "Body Composition Measurement"},
+ {"2A9D", "Weight Measurement"},
+ {"2AA2", "Language"},
+ {"2AA4", "Bond Management Control Point"},
+ {"2AA5", "Bond Management Features"},
+ {"2AA6", "Central Address Resolution"},
+ {"2AAD", "Indoor Positioning Configuration"},
+ {"2AB5", "Location Name"},
+ {"2AB6", "URI"},
+ {"2ABC", "TDS Control Point"},
+ {"2AC9", "Resolvable Private Address Only"},
+ {"2ACC", "Fitness Machine Feature"},
+ {"2ACE", "Cross Trainer Data"},
+ {"2AD3", "Training Status"},
+ {"2AD7", "Supported Heart Rate Range"},
+ {"2AD9", "Fitness Machine Control Point"},
+ {"2ADA", "Fitness Machine Status"},
+ {"2B1D", "RC Feature"},
+ {"2B1E", "RC Settings"},
+ {"2B1F", "Reconnection Configuration Control Point"},
+ };
+ static uuid_name_s long_uuid_name[LONG_UUID_COUNT] = {
+ // List should be sorted by UUID
+ /* Custom uuids */
+ {"1AB7C24D-185A-45B9-90D4-F7AB1A71949A", "Samsung Health Service"},
+ {"22EAC6E9-24D6-4BB5-BE44-B36ACE7C7BFB", "Data Source"},
+ {"2F7CABCE-808D-411F-9A0C-BB92BA96C102", "Entity Update"},
+ {"32D1955A-E5AA-4A96-9A49-08538DA8B8F6", "Samsung Gear Fit Manager Service"},
+ {"69D1D8F3-45E1-49A8-9821-9BBDFDAAD9D9", "Control Point"},
+ {"7905F431-B5CE-4E99-A40F-4B1E122D00D0", "Apple Notification Center Service"},
+ {"89D3502B-0F36-433A-8EF4-C502AD55F8DC", "Apple Media Service"},
+ {"9A3F68E0-86CE-11E5-A309-0002A5D5C51B", "Samsung Gear Manager Service"},
+ {"9B3C81D8-57B1-4A8A-B8DF-0E56F7CA51C2", "Remote Command"},
+ {"9FBF120D-6301-42D9-8C58-25E699A21DBD", "Notifications Source"},
+ {"A49EB41E-CB06-495C-9F4F-BB80A90CDF00", "Samsung Gear Manager Service"},
+ {"ADE3D529-C784-4F63-A987-EB69F70EE816", "IoT OIC Service"},
+ {"C2051EE0-804D-4D50-A12C-15E243852100", "Notifications Source"},
+ {"C2F2CC0F-C085-4DD4-BE5A-ACA3074BBC72", "Control Point"},
+ {"C6B2F38C-23AB-46D8-A6AB-A3A870BBD5D7", "Entity Attribute"},
+ {"CECE518B-28D7-4171-92D5-76A1E249A3B9", "Notifications Source"},
+ {"FE53FF98-B259-4337-B56A-0EC9F82C6BAD", "Control Point"},
+ };
+ const uuid_name_s *uuid_name = short_uuid_name;
+ static const char *unknown_name = "Unknown";
+ int start = 0;
+ int end = SHORT_UUID_COUNT - 1;
+ int p;
+ int ret;
+
+ if (strlen(uuid) == 36) {
+ if (!g_ascii_strncasecmp(uuid + 9, "0000-1000-8000-00805F9B34FB", 27))
+ offset = 4;
+ else {
+ offset = 0;
+ uuid_len = 36;
+ end = LONG_UUID_COUNT - 1;
+ uuid_name = long_uuid_name;
+ }
+ } else if (strlen(uuid) >= 8)
+ offset = 4;
+
+ while (start <= end) {
+ p = start + (end - start) / 2;
+ ret = g_ascii_strncasecmp(uuid + offset, uuid_name[p].uuid, uuid_len);
+ if (ret == 0)
+ return uuid_name[p].specification_name;
+ else if (ret < 0)
+ end = p - 1;
+ else
+ start = p + 1;
+ }
+
+ return unknown_name;
+}
+
+const char *_bt_convert_error_to_string(int error)
+{
+ switch (error) {
+ case BLUETOOTH_ERROR_CANCEL:
+ return "CANCELLED";
+ case BLUETOOTH_ERROR_INVALID_PARAM:
+ return "INVALID_PARAMETER";
+ case BLUETOOTH_ERROR_INVALID_DATA:
+ return "INVALID DATA";
+ case BLUETOOTH_ERROR_MEMORY_ALLOCATION:
+ case BLUETOOTH_ERROR_OUT_OF_MEMORY:
+ return "OUT_OF_MEMORY";
+ case BLUETOOTH_ERROR_TIMEOUT:
+ return "TIMEOUT";
+ case BLUETOOTH_ERROR_NO_RESOURCES:
+ return "NO_RESOURCES";
+ case BLUETOOTH_ERROR_INTERNAL:
+ return "INTERNAL";
+ case BLUETOOTH_ERROR_NOT_SUPPORT:
+ return "NOT_SUPPORT";
+ case BLUETOOTH_ERROR_DEVICE_NOT_ENABLED:
+ return "NOT_ENABLED";
+ case BLUETOOTH_ERROR_DEVICE_ALREADY_ENABLED:
+ return "ALREADY_ENABLED";
+ case BLUETOOTH_ERROR_DEVICE_BUSY:
+ return "DEVICE_BUSY";
+ case BLUETOOTH_ERROR_ACCESS_DENIED:
+ return "ACCESS_DENIED";
+ case BLUETOOTH_ERROR_MAX_CLIENT:
+ return "MAX_CLIENT";
+ case BLUETOOTH_ERROR_NOT_FOUND:
+ return "NOT_FOUND";
+ case BLUETOOTH_ERROR_SERVICE_SEARCH_ERROR:
+ return "SERVICE_SEARCH_ERROR";
+ case BLUETOOTH_ERROR_PARING_FAILED:
+ return "PARING_FAILED";
+ case BLUETOOTH_ERROR_NOT_PAIRED:
+ return "NOT_PAIRED";
+ case BLUETOOTH_ERROR_SERVICE_NOT_FOUND:
+ return "SERVICE_NOT_FOUND";
+ case BLUETOOTH_ERROR_NOT_CONNECTED:
+ return "NOT_CONNECTED";
+ case BLUETOOTH_ERROR_ALREADY_CONNECT:
+ return "ALREADY_CONNECT";
+ case BLUETOOTH_ERROR_CONNECTION_BUSY:
+ return "CONNECTION_BUSY";
+ case BLUETOOTH_ERROR_CONNECTION_ERROR:
+ return "CONNECTION_ERROR";
+ case BLUETOOTH_ERROR_MAX_CONNECTION:
+ return "MAX_CONNECTION";
+ case BLUETOOTH_ERROR_NOT_IN_OPERATION:
+ return "NOT_IN_OPERATION";
+ case BLUETOOTH_ERROR_CANCEL_BY_USER:
+ return "CANCEL_BY_USER";
+ case BLUETOOTH_ERROR_REGISTRATION_FAILED:
+ return "REGISTRATION_FAILED";
+ case BLUETOOTH_ERROR_IN_PROGRESS:
+ return "IN_PROGRESS";
+ case BLUETOOTH_ERROR_AUTHENTICATION_FAILED:
+ return "AUTHENTICATION_FAILED";
+ case BLUETOOTH_ERROR_HOST_DOWN:
+ return "HOST_DOWN";
+ case BLUETOOTH_ERROR_END_OF_DEVICE_LIST:
+ return "END_OF_DEVICE_LIST";
+ case BLUETOOTH_ERROR_AGENT_ALREADY_EXIST:
+ return "AGENT_ALREADY_EXIST";
+ case BLUETOOTH_ERROR_AGENT_DOES_NOT_EXIST:
+ return "AGENT_DOES_NOT_EXIST";
+ case BLUETOOTH_ERROR_ALREADY_INITIALIZED:
+ return "ALREADY_INITIALIZED";
+ case BLUETOOTH_ERROR_PERMISSION_DEINED:
+ return "PERMISSION_DEINED";
+ case BLUETOOTH_ERROR_ALREADY_DEACTIVATED:
+ return "ALREADY_DEACTIVATED";
+ case BLUETOOTH_ERROR_NOT_INITIALIZED:
+ return "NOT_INITIALIZED";
+ case BLUETOOTH_ERROR_AUTHENTICATION_REJECTED:
+ return "AUTHENTICATION REJECTED";
+ case BLUETOOTH_ERROR_AUTHORIZATION_REJECTED:
+ return "AUTHORIZATION REJECTED";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+const char *_bt_convert_disc_reason_to_string(int reason)
+{
+ switch (reason) {
+ case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
+ return "Page timeout";
+ case (int)BLUETOOTH_ERROR_AUTH_FAILURE:
+ return "Authentication Failure";
+ case (int)BLUETOOTH_ERROR_PIN_OR_KEY_MISSING:
+ return "PIN or Key missing";
+ case (int)BLUETOOTH_ERROR_CONNECTION_TIMEOUT:
+ return "Link loss";
+ case (int)BLUETOOTH_ERROR_CONNECTION_REJECTED_DUE_TO_SECURITY_REASONS:
+ return "Connection rejected due to security reasons";
+ case (int)BLUETOOTH_ERROR_REMOTE_USER_TERM:
+ case (int)BLUETOOTH_ERROR_REMOTE_LOW_RESOURCES:
+ case (int)BLUETOOTH_ERROR_REMOTE_POWER_OFF:
+ return "Remote user terminated connection";
+ case (int)BLUETOOTH_ERROR_LOCAL_HOST_TERM:
+ return "Connection terminated by local host";
+ case (int)BLUETOOTH_ERROR_REPEATED_ATTEMPTS:
+ return "Repeated attempts";
+ case (int)BLUETOOTH_ERROR_LMP_RESPONSE_TIMEOUT:
+ return "LMP response timeout";
+ case (int)BLUETOOTH_ERROR_LMP_TRANSACTION_COLLISION:
+ return "LMP transaction collision";
+ case (int)BLUETOOTH_ERROR_INSTANT_PASSED:
+ return "Instant passed";
+ case (int)BLUETOOTH_ERROR_INSUFFICIENT_SECURITY:
+ return "Insufficient security";
+ case (int)BLUETOOTH_ERROR_CONNECTION_TERMINATED_DUE_TO_MIC_FAILURE:
+ return "Connection terminated due to MIC failure";
+ case (int)BLUETOOTH_ERROR_CONNECTION_FAILED_TO_BE_ESTABLISHED:
+ return "Connection failed to be established";
+ default:
+ return "Unknown";