Create temporary file to check wifi firmware state 63/191363/2 submit/tizen/20181022.053844
authorSeonah Moon <seonah1.moon@samsung.com>
Tue, 16 Oct 2018 08:32:29 +0000 (17:32 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Tue, 16 Oct 2018 08:52:08 +0000 (17:52 +0900)
If net-config is finished unexpectly, it restarts.
And then wifi firmware is downloaded although it is already loaded.

This patch creates the file to check whether wifi firmware is loaded or not.

Change-Id: I4d8dbc4538d28d2c0eef7f945947bf007e47c73d

packaging/net-config.spec
src/wifi.c

index c37ef80..716d7d5 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          net-config
 Summary:       TIZEN Network Configuration service
-Version:       1.1.136
+Version:       1.1.137
 Release:       3
 Group:         System/Network
 License:       Apache-2.0
index d47a352..bb22a4e 100755 (executable)
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <vconf.h>
 #include <vconf-keys.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "log.h"
 #include "wifi.h"
@@ -46,6 +48,7 @@
 #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;
@@ -111,6 +114,26 @@ void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
        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;
@@ -118,13 +141,13 @@ int wifi_firmware_download(void)
        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");
        }