return BT_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
}
- int ret;
+ char str_ptr[36] = { 0 };
+ char *ptr[7];
+ char *next_ptr;
+ char *stop;
+ int idx = 0;
+
unsigned int val0, val4;
unsigned short val1, val2, val3, val5;
data = g_malloc0(sizeof(char) *16);
if (data == NULL)
return BT_ERROR_OUT_OF_MEMORY;
- ret = sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
- &val0, &val1, &val2, &val3, &val4, &val5);
- if (ret != 6) {
- g_free(data);
- return BT_ERROR_OPERATION_FAILED;
+ /* UUID format : %08x-%04hx-%04hx-%04hx-%08x%04hx */
+ strncpy(str_ptr, string, 36);
+
+ ptr[idx++] = strtok_r(str_ptr, "-", &next_ptr);
+ while ((ptr[idx++] = strtok_r(NULL, "-", &next_ptr)) != NULL) {
+ BT_INFO("ptr : %s", ptr[idx - 1]);
+ if (idx == 5)
+ break;
}
+ /* ptr[4] contain "08x" and "04hx" */
+ ptr[5] = g_malloc0(sizeof(char) * 8);
+ ptr[6] = g_malloc0(sizeof(char) * 4);
+ strncpy(ptr[5], ptr[4], 8);
+ strncpy(ptr[6], ptr[4] + 8, 4);
+
+ val0 = strtol(ptr[0], &stop, 16);
+ val1 = strtol(ptr[1], &stop, 16);
+ val2 = strtol(ptr[2], &stop, 16);
+ val3 = strtol(ptr[3], &stop, 16);
+ val4 = strtol(ptr[5], &stop, 16);
+ val5 = strtol(ptr[6], &stop, 16);
+
val0 = htonl(val0);
val1 = htons(val1);
val2 = htons(val2);
val4 = htonl(val4);
val5 = htons(val5);
+ BT_INFO("%x, %x, %x, %x, %x, %x", val0, val1, val2, val3, val4, val5);
+
memcpy(data, &val0, 4);
memcpy(data + 4, &val1, 2);
memcpy(data + 6, &val2, 2);
*uuid = data;
*bit = 128;
+
+ g_free(ptr[5]);
+ g_free(ptr[6]);
} else {
BT_ERR("Invalid UUID"); /* LCOV_EXCL_LINE */
return BT_ERROR_INVALID_PARAMETER; /* LCOV_EXCL_LINE */
void _bt_convert_address_to_hex(bluetooth_device_address_t *addr_hex, const char *addr_str)
{
- int i = 0;
- unsigned int addr[BLUETOOTH_ADDRESS_LENGTH] = { 0, };
+ char *ptr1, *ptr2, *ptr3, *ptr4, *ptr5;
if (addr_str == NULL || addr_str[0] == '\0')
- return; /* LCOV_EXCL_LINE */
-
- i = sscanf(addr_str, "%X:%X:%X:%X:%X:%X", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]);
- if (i != BLUETOOTH_ADDRESS_LENGTH)
- BT_ERR("Invalid format string - [%s]", addr_str); /* LCOV_EXCL_LINE */
+ return;
- for (i = 0; i < BLUETOOTH_ADDRESS_LENGTH; i++)
- addr_hex->addr[i] = (unsigned char)addr[i];
+ addr_hex->addr[0] = strtol(addr_str, &ptr5, 16);
+ addr_hex->addr[1] = strtol(ptr5 + 1, &ptr4, 16);
+ addr_hex->addr[2] = strtol(ptr4 + 1, &ptr3, 16);
+ addr_hex->addr[3] = strtol(ptr3 + 1, &ptr2, 16);
+ addr_hex->addr[4] = strtol(ptr2 + 1, &ptr1, 16);
+ addr_hex->addr[5] = strtol(ptr1 + 1, NULL, 16);
}
char *_bt_convert_error_to_string(int error)