#include "hal-api-compatibility-checker-object.h"
#include "hal-api-compatibility-checker-parser.h"
-#define HAL_CC_DEFAULT_HAL_MANIFEST_DIR "/etc/hal"
#define HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH "/opt/etc/hal/.hal-backend-compatibility"
#define COMPAT_INFO_MODULE_NAME_MAX 64
struct compatibility_info {
+ bool initialized;
char module_name[COMPAT_INFO_MODULE_NAME_MAX];
int version_list[HALCC_NUM_VERSION_LIST_MAX][2];
int num_version_list;
enum hal_common_backend_compatibility compatibility;
};
-static const char *manifest_directory = HAL_CC_DEFAULT_HAL_MANIFEST_DIR;
static const char *compatibility_result_path = HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH;
-void set_compatibility_manifest_directory(const char *path)
-{
- if (!path)
- return;
-
- manifest_directory = path;
-}
-
-void unset_compatibility_manifest_directory(void)
-{
- manifest_directory = HAL_CC_DEFAULT_HAL_MANIFEST_DIR;
-}
-
void set_compatibility_result_path(const char *path)
{
if (!path)
if (halcc_hal_is_compatible_with_version(hal, major, minor))
info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE;
+
+ info->initialized = true;
}
static void convert_hal_to_info(void *data_hal, void *data_info)
// copy path except the last filename
strncpy(directory_path, path, strrchr(path, '/') - path);
+ if (access(directory_path, F_OK) == 0)
+ return 0;
+
p = strchr(directory_path + 1, '/');
for (;;) {
if (!p)
}
-static int write_comaptibility_info(struct compatibility_info *info, int entry_size)
+static int open_result_file(const char *path, int *fd_out, bool reset)
{
- int fd = -1;
int ret;
- ssize_t n_write;
+ int fd;
+ mode_t mode = O_WRONLY | O_CREAT;
- ret = create_directory(compatibility_result_path);
+ if (reset)
+ mode |= O_TRUNC;
+ else
+ mode |= O_EXCL;
+
+ ret = create_directory(path);
if (ret < 0) {
errno = -ret;
- _E("Failed to create directory for %s, %m",
- compatibility_result_path);
+ _E("Failed to create directory for %s, %m", path);
return ret;
}
- fd = open(compatibility_result_path,
- O_WRONLY | O_CREAT | O_EXCL, 0644);
+ fd = open(path, mode, 0644);
if (fd == -1) {
- _E("Failed to create %s, %m",
- compatibility_result_path);
+ if (errno == EEXIST) {
+ /* file exists and reset is false: use that one */
+ fd = open(path, O_WRONLY, 0);
+ if (fd == -1)
+ return -errno;
+
+ *fd_out = fd;
+ return 0;
+ }
+
+ _E("Failed to create %s, %m", path);
return -errno;
}
- ret = set_owner(fd); // system_fw:system_fw
+ /* set a new file size */
+ ret = ftruncate(fd, sizeof(struct compatibility_info) * HAL_MODULE_END);
+ if (ret < 0) {
+ _E("Failed to ftruncate %s, %m", path);
+ return -errno;
+ }
+
+ /* system_fw:system_fw */
+ ret = set_owner(fd);
if (ret < 0) {
errno = -ret;
_E("Failed to set owner, ret=%d, %m\n", ret);
return ret;
}
- n_write = write(fd, info, sizeof(struct compatibility_info) * entry_size);
+ *fd_out = fd;
+
+ return 0;
+}
+
+static int write_module_comaptibility_info(enum hal_module module,
+ struct compatibility_info *info)
+{
+ int fd = -1;
+ int ret;
+ ssize_t n_write;
+ off_t offset;
+
+ ret = open_result_file(compatibility_result_path, &fd, false);
+ if (ret < 0) {
+ _E("Failed to create open result file %s", compatibility_result_path);
+ return ret;
+ }
+
+ offset = sizeof(struct compatibility_info) * module;
+ n_write = pwrite(fd, info, sizeof(*info), offset);
if (n_write == -1) {
_E("Failed to write info, %m");
close(fd);
close(fd);
+ if (!info->initialized)
+ return -ENODATA;
+
return 0;
}
{
halcc_manifest *manifest = NULL;
struct compatibility_info infos[HAL_MODULE_END] = { 0 , };
+ struct __hal_module_info *module_info = NULL;
int ret;
- assert(module >= HAL_MODULE_UNKNOWN);
- assert(module < HAL_MODULE_END);
assert(info);
+ if (_hal_api_conf_init()) {
+ return -ENODATA;
+ }
+
+ module_info = _hal_api_conf_get_module_info(module, NULL);
+ if (!module_info || !module_info->manifest) {
+ _hal_api_conf_exit();
+ return -EINVAL;
+ }
+
+ _hal_api_conf_exit();
+
ret = halcc_manifest_new(&manifest);
if (ret < 0)
return ret;
- ret = halcc_parse_directory(manifest_directory, manifest);
+ ret = halcc_parse_path(module_info->manifest, manifest);
if (ret < 0) {
halcc_manifest_free(manifest);
return ret;
if (skip_version_check)
return 0;
- return write_comaptibility_info(infos, HAL_MODULE_END);
+ /* Write all available(initialized) info */
+ for (enum hal_module index = HAL_MODULE_UNKNOWN; index < HAL_MODULE_END; ++index) {
+ if (!infos[index].initialized)
+ continue;
+ write_module_comaptibility_info(index, &infos[index]);
+ }
+
+ return 0;
}
int hal_api_cc_check_backend_compatibility(enum hal_module module,
.library_name = "/hal/lib/libhal-backend-tbm.so",
.library_name_64bit = "/hal/lib64/libhal-backend-tbm.so",
.symbol_name = "hal_backend_tbm_data",
+ .manifest = "/etc/hal/hal-api-tbm-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_TDM] = {
.library_name = "/hal/lib/libhal-backend-tdm.so",
.library_name_64bit = "/hal/lib64/libhal-backend-tdm.so",
.symbol_name = "hal_backend_tdm_data",
+ .manifest = "/etc/hal/hal-api-tdm-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_COREGL] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
[HAL_MODULE_INPUT] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
.library_name = "/hal/lib/libhal-backend-audio.so",
.library_name_64bit = "/hal/lib64/libhal-backend-audio.so",
.symbol_name = "hal_backend_audio_data",
+ .manifest = "/etc/hal/hal-api-audio-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_CAMERA] = {
.library_name = "/hal/lib/libhal-backend-camera.so",
.library_name_64bit = "/hal/lib64/libhal-backend-camera.so",
.symbol_name = "hal_backend_camera_data",
+ .manifest = "/etc/hal/hal-api-camera-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_RADIO] = {
.library_name = "/hal/lib/libhal-backend-radio.so",
.library_name_64bit = "/hal/lib64/libhal-backend-radio.so",
.symbol_name = "hal_backend_radio_data",
+ .manifest = "/etc/hal/hal-api-radio-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_CODEC] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
[HAL_MODULE_USB_AUDIO] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
[HAL_MODULE_ALSAUCM] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
.library_name = "/hal/lib/libhal-backend-bluetooth.so",
.library_name_64bit = "/hal/lib64/libhal-backend-bluetooth.so",
.symbol_name = "hal_backend_bluetooth_data",
+ .manifest = "/etc/hal/hal-api-bluetooth-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_WIFI] = {
.library_name = "/hal/lib/libhal-backend-wifi.so",
.library_name_64bit = "/hal/lib64/libhal-backend-wifi.so",
.symbol_name = "hal_backend_wifi_data",
+ .manifest = "/etc/hal/hal-api-wifi-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_NAN] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
[HAL_MODULE_NFC] = {
.library_name = "/hal/lib/libhal-backend-nfc.so",
.library_name_64bit = "/hal/lib64/libhal-backend-nfc.so",
.symbol_name = "hal_backend_nfc_data",
+ .manifest = "/etc/hal/hal-api-nfc-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_ZIGBEE] = {
.library_name = "/hal/lib/libhal-backend-zigbee.so",
.library_name_64bit = "/hal/lib64/libhal-backend-zigbee.so",
.symbol_name = "hal_backend_zigbee_data",
+ .manifest = "/etc/hal/hal-api-zigbee-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_UWB] = {
.library_name = "/hal/lib/libhal-backend-uwb.so",
.library_name_64bit = "/hal/lib64/libhal-backend-uwb.so",
.symbol_name = "hal_backend_uwb_data",
+ .manifest = "/etc/hal/hal-api-uwb-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_MTP] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
.library_name = "/hal/lib/libhal-backend-location.so",
.library_name_64bit = "/hal/lib64/libhal-backend-location.so",
.symbol_name = "hal_backend_location_data",
+ .manifest = "/etc/hal/hal-api-location-manifest.xml",
.hal_api = true,
},
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = true,
},
[HAL_MODULE_POWER] = {
.library_name = "/hal/lib/libhal-backend-power.so",
.library_name_64bit = "/hal/lib64/libhal-backend-power.so",
.symbol_name = "hal_backend_power_data",
+ .manifest = "/etc/hal/hal-api-power-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_SENSOR] = {
.library_name = "/hal/lib/libhal-backend-sensor.so",
.library_name_64bit = "/hal/lib64/libhal-backend-sensor.so",
.symbol_name = "hal_backend_sensor_data",
+ .manifest = "/etc/hal/hal-api-sensor-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_PERIPHERAL] = {
.library_name = NULL,
.library_name_64bit = NULL,
.symbol_name = NULL,
+ .manifest = NULL,
.hal_api = false,
},
[HAL_MODULE_DEVICE_BATTERY] = {
.library_name = "/hal/lib/libhal-backend-device-battery.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-battery.so",
.symbol_name = "hal_backend_device_battery_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_BEZEL] = {
.library_name = "/hal/lib/libhal-backend-device-bezel.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-bezel.so",
.symbol_name = "hal_backend_device_bezel_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_DISPLAY] = {
.library_name = "/hal/lib/libhal-backend-device-display.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-display.so",
.symbol_name = "hal_backend_device_display_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_IR] = {
.library_name = "/hal/lib/libhal-backend-device-ir.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-ir.so",
.symbol_name = "hal_backend_device_ir_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_TOUCHSCREEN] = {
.library_name = "/hal/lib/libhal-backend-device-touchscreen.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-touchscreen.so",
.symbol_name = "hal_backend_device_touchscreen_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_LED] = {
.library_name = "/hal/lib/libhal-backend-device-led.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-led.so",
.symbol_name = "hal_backend_device_led_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_BOARD] = {
.library_name = "/hal/lib/libhal-backend-device-board.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-board.so",
.symbol_name = "hal_backend_device_board_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_EXTERNAL_CONNECTION] = {
.library_name = "/hal/lib/libhal-backend-device-external-connection.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-external-connection.so",
.symbol_name = "hal_backend_device_external_connection_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_THERMAL] = {
.library_name = "/hal/lib/libhal-backend-device-thermal.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-thermal.so",
.symbol_name = "hal_backend_device_thermal_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_USB_GADGET] = {
.library_name = "/hal/lib/libhal-backend-device-usb-gadget.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-usb-gadget.so",
.symbol_name = "hal_backend_device_usb_gadget_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_HAPTIC] = {
.library_name = "/hal/lib/libhal-backend-device-haptic.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-haptic.so",
.symbol_name = "hal_backend_device_haptic_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_MEMORY] = {
.library_name = "/hal/lib/libhal-backend-device-memory.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-memory.so",
.symbol_name = "hal_backend_device_memory_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_INPUT] = {
.library_name = "/hal/lib/libhal-backend-device-input.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-input.so",
.symbol_name = "hal_backend_device_input_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
[HAL_MODULE_DEVICE_POWER] = {
.library_name = "/hal/lib/libhal-backend-device-power.so",
.library_name_64bit = "/hal/lib64/libhal-backend-device-power.so",
.symbol_name = "hal_backend_device_power_data",
+ .manifest = "/etc/hal/hal-api-device-manifest.xml",
.hal_api = true,
},
};