#include <unistd.h>
#include <vconf.h>
#include <vconf-keys.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "log.h"
#include "wifi.h"
#include "wifi-extension.h"
#define SPRD_CP2_FIRMWARE_PATH "/usr/bin/cp2-downloader"
+#define SPRD_CP2_FIRMWARE_STATE_PATH "/tmp/.wifi-firmware-loaded"
static int is_wifi_firmware_downloaded = FALSE;
static Wifi *wifi_object = NULL;
return;
}
+static void _update_wifi_firmware_state(void)
+{
+ mode_t mode = S_IRGRP | S_IWUSR | S_IXGRP;
+
+ if (creat(SPRD_CP2_FIRMWARE_STATE_PATH, mode) < 0)
+ DBG("Failed to create wifi firmware state file");
+
+ is_wifi_firmware_downloaded = TRUE;
+}
+
+static int _get_wifi_firmware_state(void)
+{
+ if (!is_wifi_firmware_downloaded
+ && access(SPRD_CP2_FIRMWARE_STATE_PATH, F_OK) != 0)
+ is_wifi_firmware_downloaded = FALSE;
+ else
+ is_wifi_firmware_downloaded = TRUE;
+ return is_wifi_firmware_downloaded;
+}
+
int wifi_firmware_download(void)
{
int rv = 0;
char *const args[] = { SPRD_CP2_FIRMWARE_PATH, NULL };
char *const envs[] = { NULL };
- if (!is_wifi_firmware_downloaded) {
+ if (!_get_wifi_firmware_state()) {
rv = netconfig_execute_file(path, args, envs);
if (rv < 0) {
DBG("wifi firmware download fails");
return -EIO;
}
- is_wifi_firmware_downloaded = TRUE;
+ _update_wifi_firmware_state();
DBG("wifi firmware download successes");
}