#include "haltest.h"
#include "hal-board.h"
+#define BUFFER_MAX 128
+
class BOARD : public testing::Test {
protected:
void SetUp() override {}
TEST_F(BOARD, GetDeviceSerialP)
{
int ret_val;
- char *serial = nullptr;
+ char serial[BUFFER_MAX] = {0, };
- ret_val = hal_device_board_get_device_serial_number(&serial);
+ ret_val = hal_device_board_get_device_serial_number(serial, sizeof(serial));
if (ret_val == -ENODEV) {
SKIP_MESSAGE("Not supported HAL");
return;
}
EXPECT_EQ(ret_val, 0) << "Failed to get device serial (" << ret_val << ")";
- EXPECT_NE(serial, nullptr) << "Failed to get device serial (nullptr)";
if (ret_val == 0 && serial)
DEBUG_MESSAGE("Serial=%s", serial);
-
- free(serial);
}
TEST_F(BOARD, GetDeviceRevisionP)
typedef struct _hal_backend_board_funcs {
/* Serial number of this device */
- int (*get_device_serial_number)(char **serial);
+ int (*get_device_serial_number)(char *buffer, int len);
int (*get_device_revision)(int *revision);
} hal_backend_board_funcs;
int hal_device_board_get_backend(void);
int hal_device_board_put_backend(void);
-int hal_device_board_get_device_serial_number(char **serial);
+int hal_device_board_get_device_serial_number(char *buffer, int len);
int hal_device_board_get_device_revision(int *revision);
#ifdef __cplusplus
return 0;
}
-int hal_device_board_get_device_serial_number(char **serial)
+int hal_device_board_get_device_serial_number(char *buffer, int len)
{
int ret ;
!hal_board_funcs->get_device_serial_number)
return -ENODEV;
- return hal_board_funcs->get_device_serial_number(serial);
+ return hal_board_funcs->get_device_serial_number(buffer, len);
}
int hal_device_board_get_device_revision(int *revision)
#include "hal-board.h"
#include "hal-usb_gadget-interface.h"
+#define SERIAL_MAX 128
+
static hal_backend_usb_gadget_funcs *hal_usb_gadget_funcs;
/*
-1 : failed to initialize
static int get_board_serial(hal_backend_usb_gadget_funcs *usb_gadget_funcs)
{
- char *board_serial = NULL;
+ char board_serial[SERIAL_MAX] = {0, };
+ int retval;
if (!usb_gadget_funcs)
return -EINVAL;
- if (hal_device_board_get_device_serial_number(&board_serial))
- _E("Failed to get board serial for USB");
-
- if (!board_serial)
- board_serial = strdup(DEFAULT_SERIAL);
+ retval = hal_device_board_get_device_serial_number(board_serial, SERIAL_MAX);
+ if (retval == 0) {
+ usb_gadget_funcs->board_serial = strndup(board_serial, SERIAL_MAX);
+ } else {
+ _E("Failed to get board serial for USB, use default serial=%s", DEFAULT_SERIAL);
+ usb_gadget_funcs->board_serial = strndup(DEFAULT_SERIAL, SERIAL_MAX);
+ }
- usb_gadget_funcs->board_serial = board_serial;
if (!usb_gadget_funcs->board_serial)
return -ENOMEM;