Bluetooth: Switch from printf to printk functions

There's now snprintk available that's more light-weight on the stack
than snprintf.

Change-Id: I6b3e4409703ca92fe6b8f4146ff47c490ab826cb
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-12-06 21:46:10 +02:00
commit a4b6b2417d
6 changed files with 23 additions and 20 deletions

View file

@ -27,6 +27,7 @@
#include <misc/util.h>
#include <misc/byteorder.h>
#include <misc/stack.h>
#include <misc/printk.h>
#include <string.h>
#include <bluetooth/bluetooth.h>
@ -246,29 +247,29 @@ static void hexdump(const char *str, const uint8_t *packet, size_t length)
int n = 0;
if (!length) {
printf("%s zero-length signal packet\n", str);
printk("%s zero-length signal packet\n", str);
return;
}
while (length--) {
if (n % 16 == 0) {
printf("%s %08X ", str, n);
printk("%s %08X ", str, n);
}
printf("%02X ", *packet++);
printk("%02X ", *packet++);
n++;
if (n % 8 == 0) {
if (n % 16 == 0) {
printf("\n");
printk("\n");
} else {
printf(" ");
printk(" ");
}
}
}
if (n % 16) {
printf("\n");
printk("\n");
}
}
#else

View file

@ -27,9 +27,8 @@
*/
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <misc/printk.h>
#include <misc/util.h>
#include <net/buf.h>
#include <bluetooth/hci.h>
@ -402,7 +401,7 @@ int bt_br_oob_get_local(struct bt_br_oob *oob);
*/
static inline int bt_addr_to_str(const bt_addr_t *addr, char *str, size_t len)
{
return snprintf(str, len, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
return snprintk(str, len, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
addr->val[5], addr->val[4], addr->val[3],
addr->val[2], addr->val[1], addr->val[0]);
}
@ -430,11 +429,11 @@ static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
strcpy(type, "random");
break;
default:
sprintf(type, "0x%02x", addr->type);
snprintk(type, sizeof(type), "0x%02x", addr->type);
break;
}
return snprintf(str, len, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X (%s)",
return snprintk(str, len, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X (%s)",
addr->a.val[5], addr->a.val[4], addr->a.val[3],
addr->a.val[2], addr->a.val[1], addr->a.val[0], type);
}

View file

@ -115,6 +115,7 @@ if BLUETOOTH_HCI_HOST
config BLUETOOTH_INTERNAL_STORAGE
bool "Use an internal persistent storage handler"
depends on FILE_SYSTEM
depends on PRINTK
help
When selected the application doesn't need to register its own
persistent storage handlers through the bt_storage API, rather
@ -464,6 +465,7 @@ config BLUETOOTH_RFCOMM_L2CAP_MTU
config BLUETOOTH_HFP_HF
bool "Bluetooth Handsfree profile HF Role support [EXPERIMENTAL]"
depends on PRINTK
select BLUETOOTH_RFCOMM
help
This option enables Bluetooth HF support

View file

@ -20,6 +20,7 @@
#include <atomic.h>
#include <misc/byteorder.h>
#include <misc/util.h>
#include <misc/printk.h>
#include <bluetooth/log.h>
#include <bluetooth/conn.h>
@ -67,7 +68,7 @@ int hfp_hf_send_cmd(struct bt_hfp_hf *hf, at_resp_cb_t resp,
}
va_start(vargs, format);
ret = vsnprintf(buf->data, (net_buf_tailroom(buf) - 1), format, vargs);
ret = vsnprintk(buf->data, (net_buf_tailroom(buf) - 1), format, vargs);
if (ret < 0) {
BT_ERR("Unable to format variable arguments");
return ret;

View file

@ -15,8 +15,8 @@
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <misc/printk.h>
#include <zephyr.h>
#include <init.h>
@ -56,7 +56,7 @@ static int storage_open(const bt_addr_le_t *addr, uint16_t key,
#if MAX_FILE_NAME >= STORAGE_FILE_NAME_LEN
int len;
len = snprintf(path, sizeof(path),
len = snprintk(path, sizeof(path),
STORAGE_ROOT "/%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%u",
addr->a.val[5], addr->a.val[4], addr->a.val[3],
addr->a.val[2], addr->a.val[1], addr->a.val[0],
@ -76,12 +76,12 @@ static int storage_open(const bt_addr_le_t *addr, uint16_t key,
}
}
snprintf(path + len, sizeof(path) - len, "/%04x", key);
snprintk(path + len, sizeof(path) - len, "/%04x", key);
#else
return -ENAMETOOLONG;
#endif
} else {
snprintf(path, sizeof(path), STORAGE_ROOT "/%04x", key);
snprintk(path, sizeof(path), STORAGE_ROOT "/%04x", key);
}
return fs_open(file, path);
@ -149,7 +149,7 @@ static int unlink_recursive(char path[STORAGE_PATH_MAX])
break;
}
snprintf(path + path_len, STORAGE_PATH_MAX - path_len, "/%s",
snprintk(path + path_len, STORAGE_PATH_MAX - path_len, "/%s",
entry.name);
if (entry.type == FS_DIR_ENTRY_DIR) {
@ -180,7 +180,7 @@ static int storage_clear(const bt_addr_le_t *addr)
if (addr) {
#if MAX_FILE_NAME >= STORAGE_FILE_NAME_LEN
snprintf(path, STORAGE_PATH_MAX,
snprintk(path, STORAGE_PATH_MAX,
STORAGE_ROOT "/%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X%u",
addr->a.val[5], addr->a.val[4], addr->a.val[3],
addr->a.val[2], addr->a.val[1], addr->a.val[0],

View file

@ -1316,7 +1316,7 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
snprintf(passkey_str, 7, "%06u", passkey);
snprintk(passkey_str, 7, "%06u", passkey);
printk("Passkey for %s: %s\n", addr, passkey_str);
}
@ -1328,7 +1328,7 @@ static void auth_passkey_confirm(struct bt_conn *conn, unsigned int passkey)
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
snprintf(passkey_str, 7, "%06u", passkey);
snprintk(passkey_str, 7, "%06u", passkey);
printk("Confirm passkey for %s: %s\n", addr, passkey_str);
}