wifi: Add support for autoscan request
[framework/connectivity/connman.git] / plugins / iwmxsdk.c
index b7dee54..06de4c3 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -24,6 +24,7 @@
 #endif
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <string.h>
 #include <net/if.h>
 #include "iwmx.h"
 
 /* Yes, this is dirty; see above on IWMX_SDK_DEV_MAX*/
-static struct wmxsdk g_iwmx_sdk_devs[IWMX_SDK_DEV_MAX];
+static struct wmxsdk *g_iwmx_sdk_devs[IWMX_SDK_DEV_MAX];
 
 static struct wmxsdk *deviceid_to_wmxsdk(WIMAX_API_DEVICE_ID *device_id)
 {
-       return container_of(device_id, struct wmxsdk, device_id);
+       unsigned cnt;
+       for (cnt = 0; cnt < IWMX_SDK_DEV_MAX; cnt++) {
+               struct wmxsdk *wmxsdk = g_iwmx_sdk_devs[cnt];
+               if (wmxsdk &&
+                   wmxsdk->device_id.deviceIndex == device_id->deviceIndex)
+                       return wmxsdk;
+       }
+       return NULL;
 }
 
 static WIMAX_API_DEVICE_ID g_api;
@@ -203,13 +211,11 @@ struct connman_network *__iwmx_sdk_get_connected_network(struct wmxsdk *wmxsdk)
                strcpy((char *) nsp_info.NSPName, "unknown");
                nw = iwmx_cm_network_available(
                        wmxsdk, "unknown",
-                       iwmx_sdk_network_type_name(WIMAX_API_UNKNOWN),
                        nsp_info.NSPName, strlen((char *) nsp_info.NSPName) + 1,
                        cinr_to_percentage(nsp_info.CINR - 10));
        } else {
                nw = iwmx_cm_network_available(
                        wmxsdk, (char *) nsp_info.NSPName,
-                       iwmx_sdk_network_type_name(nsp_info.networkType),
                        nsp_info.NSPName, strlen((char *) nsp_info.NSPName) + 1,
                        cinr_to_percentage(nsp_info.CINR - 10));
        }
@@ -593,7 +599,6 @@ static void __iwmx_sdk_scan_common_cb(WIMAX_API_DEVICE_ID *device_id,
 
                __iwmx_cm_network_available(
                        wmxsdk, station_name,
-                       iwmx_sdk_network_type_name(nsp_info->networkType),
                        nsp_info->NSPName,
                        strlen((char *) nsp_info->NSPName) + 1,
                        strength);
@@ -814,13 +819,19 @@ static void iwmx_sdk_dev_add(unsigned idx, unsigned api_idx, const char *name)
                              idx, IWMX_SDK_DEV_MAX);
                goto error_bug;
        }
-       wmxsdk = &g_iwmx_sdk_devs[idx];
-       if (wmxsdk->dev != NULL) {
+       if (g_iwmx_sdk_devs[idx] != NULL) {
                connman_error("BUG! device index %u already enumerated?\n",
                              idx);
                goto error_bug;
        }
 
+       wmxsdk = malloc(sizeof(*wmxsdk));
+       if (wmxsdk == NULL) {
+               connman_error("Can't allocate %zu bytes\n",
+                             sizeof(*wmxsdk));
+               goto error_bug;
+       }
+
        memset(wmxsdk, 0, sizeof(*wmxsdk));
        wmxsdk_init(wmxsdk);
        /*
@@ -863,6 +874,7 @@ static void iwmx_sdk_dev_add(unsigned idx, unsigned api_idx, const char *name)
                              wmxsdk->ifname, result);
                goto error_dev_add;
        }
+       g_iwmx_sdk_devs[idx] = wmxsdk;
        return;
 
 error_dev_add:
@@ -884,7 +896,7 @@ static void iwmx_sdk_dev_rm(unsigned idx)
                              idx, IWMX_SDK_DEV_MAX);
                goto error_bug;
        }
-       wmxsdk = &g_iwmx_sdk_devs[idx];
+       wmxsdk = g_iwmx_sdk_devs[idx];
        if (wmxsdk->dev == NULL) {
                DBG("device index %u not enumerated? ignoring\n", idx);
                goto error_bug;
@@ -894,6 +906,8 @@ static void iwmx_sdk_dev_rm(unsigned idx)
        wmxsdk->name[0] = 0;
        connman_device_unref(wmxsdk->dev);
        memset(wmxsdk, 0, sizeof(*wmxsdk));
+       g_iwmx_sdk_devs[idx] = NULL;
+       free(wmxsdk);
 error_bug:
        return;
 }