Change the name of dbus property of EIR manufacturer data
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-common.c
index d17c6af..ac97955 100644 (file)
@@ -89,6 +89,9 @@ GDBusConnection *_bt_gdbus_init_session_gconn(void)
 {
        GError *error = NULL;
 
+       if (!g_thread_supported())
+               g_thread_init(NULL);
+
        dbus_threads_init_default();
 
        if (session_conn != NULL)
@@ -426,9 +429,16 @@ void _bt_convert_addr_string_to_secure_string(char *addr,
        ret_if(len != BT_ADDRESS_STRING_SIZE - 1);
 
        strncpy(addr, address, len);
+       addr[len] = '\0';
 
-       addr[len-1] = 'X';
-       addr[len-2] = 'X';
+       addr[len-7] = 'X';
+       addr[len-8] = 'X';
+       addr[len-10] = 'X';
+       addr[len-11] = 'X';
+       addr[len-13] = 'X';
+       addr[len-14] = 'X';
+       addr[len-16] = 'X';
+       addr[len-17] = 'X';
 
        return;
 }
@@ -685,7 +695,250 @@ char *_bt_get_profile_uuid128(bt_profile_type_t profile_type)
        };
 }
 
-char *_bt_convert_error_to_string(int error)
+const char *_bt_convert_uuid_to_string(const char *uuid)
+{
+#define SHORT_UUID_COUNT       162
+#define LONG_UUID_COUNT                17
+
+       if (!uuid)
+               return NULL;
+
+       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"},
+
+               /* 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"},
+       };
+       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;
+       }
+
+       BT_INFO("Unknown uuid : %s", uuid);
+       return unknown_name;
+}
+
+const char *_bt_convert_error_to_string(int error)
 {
        switch (error) {
        case BLUETOOTH_ERROR_CANCEL:
@@ -768,7 +1021,7 @@ char *_bt_convert_error_to_string(int error)
        }
 }
 
-char * _bt_convert_disc_reason_to_string(int reason)
+const char *_bt_convert_disc_reason_to_string(int reason)
 {
        switch (reason) {
        case (int)BLUETOOTH_ERROR_PAGE_TIMEOUT:
@@ -789,6 +1042,14 @@ char * _bt_convert_disc_reason_to_string(int reason)
                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:
@@ -796,6 +1057,24 @@ char * _bt_convert_disc_reason_to_string(int reason)
        }
 }
 
+const char *_bt_convert_profile_state_to_string(bt_profile_state_t state)
+{
+       switch (state) {
+       case BT_PROFILE_STATE_UNAVAILABLE:
+               return "UNAVAILABLE";
+       case BT_PROFILE_STATE_DISCONNECTED:
+               return "DISCONNECTED";
+       case BT_PROFILE_STATE_CONNECTING:
+               return "CONNECTING";
+       case BT_PROFILE_STATE_CONNECTED:
+               return "CONNECTED";
+       case BT_PROFILE_STATE_DISCONNECTING:
+               return "DISCONNECTING";
+       }
+
+       return NULL;
+}
+
 void _bt_logging_connection(gboolean connect, int addr_type)
 {
        static int le_conn = 0;
@@ -868,7 +1147,8 @@ int _bt_eventsystem_set_value(const char *event, const char *key, const char *va
 {
        int ret = ES_R_OK;
 /* Send event system event in bt-core process because bt-service's permission is not system in now */
-\r#if 0
+
+#if 0
        bundle *b = NULL;
 
        b = bundle_create();
@@ -904,7 +1184,7 @@ void __bt_get_auth_info(GVariant *reply, char *auth_info)
                is_alias_set = FALSE;
        }
        if (is_alias_set == FALSE) {
-               tmp_value = g_variant_lookup_value(reply, "ManufacturerDataLen",
+               tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerDataLen",
                                                                G_VARIANT_TYPE_UINT16);
                if (tmp_value) {
                        manufacturer_data_len = g_variant_get_uint16(tmp_value);
@@ -917,7 +1197,7 @@ void __bt_get_auth_info(GVariant *reply, char *auth_info)
                } else
                        manufacturer_data_len = 0;
 
-               tmp_value = g_variant_lookup_value(reply, "ManufacturerData",
+               tmp_value = g_variant_lookup_value(reply, "LegacyManufacturerData",
                                                                G_VARIANT_TYPE_ARRAY);
                if (tmp_value) {
                        if ((manufacturer_data_len == 0) ||