summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChengyi Zhao <chengyi1.zhao@archermind.com>2013-07-10 17:54:32 +0800
committerZhang zhengguang <zhengguang.zhang@intel.com>2013-07-12 16:28:11 +0800
commit0865b085d44beb197d0b0d79c3335941868b2a7d (patch)
tree8e6ffde06faa8347a598dd8d3241b9aff7e23d17
parent5832e8fd04b57c7b4e7e01f3b0464bcf523a3401 (diff)
downloadconnman-0865b085d44beb197d0b0d79c3335941868b2a7d.tar.gz
connman-0865b085d44beb197d0b0d79c3335941868b2a7d.tar.bz2
connman-0865b085d44beb197d0b0d79c3335941868b2a7d.zip
Tethering: Add station information management feature
-rw-r--r--include/technology.h4
-rw-r--r--plugins/wifi.c13
-rw-r--r--src/tethering.c88
3 files changed, 105 insertions, 0 deletions
diff --git a/include/technology.h b/include/technology.h
index 9fe994cd..b724cbfd 100644
--- a/include/technology.h
+++ b/include/technology.h
@@ -36,6 +36,10 @@ extern "C" {
struct connman_technology;
+int connman_technology_tethering_add_station(enum connman_service_type type,
+ const char *mac);
+int connman_technology_tethering_remove_station(const char *mac);
+
void connman_technology_tethering_notify(struct connman_technology *technology,
connman_bool_t enabled);
int connman_technology_set_regdom(const char *alpha2);
diff --git a/plugins/wifi.c b/plugins/wifi.c
index c50945b8..bbcb1df3 100644
--- a/plugins/wifi.c
+++ b/plugins/wifi.c
@@ -1909,6 +1909,17 @@ static void network_changed(GSupplicantNetwork *network, const char *property)
#endif
}
+static void add_station(const char *mac)
+{
+ connman_technology_tethering_add_station(CONNMAN_SERVICE_TYPE_WIFI,
+ mac);
+}
+
+static void remove_station(const char *mac)
+{
+ connman_technology_tethering_remove_station(mac);
+}
+
static void debug(const char *str)
{
if (getenv("CONNMAN_SUPPLICANT_DEBUG"))
@@ -1926,6 +1937,8 @@ static const GSupplicantCallbacks callbacks = {
.network_added = network_added,
.network_removed = network_removed,
.network_changed = network_changed,
+ .add_station = add_station,
+ .remove_station = remove_station,
.debug = debug,
};
diff --git a/src/tethering.c b/src/tethering.c
index 7042040c..3f9c10bf 100644
--- a/src/tethering.c
+++ b/src/tethering.c
@@ -29,6 +29,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
+#include <stdbool.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <linux/sockios.h>
@@ -52,6 +53,9 @@
#define DEFAULT_MTU 1500
+#define CONNMAN_STATION_STR_INFO_LEN 64
+#define CONNMAN_STATION_MAC_INFO_LEN 32
+
static char *private_network_primary_dns = NULL;
static char *private_network_secondary_dns = NULL;
@@ -60,6 +64,7 @@ static GDHCPServer *tethering_dhcp_server = NULL;
static struct connman_ippool *dhcp_ippool = NULL;
static DBusConnection *connection;
static GHashTable *pn_hash;
+static GHashTable *sta_hash;
struct connman_private_network {
char *owner;
@@ -76,6 +81,84 @@ struct connman_private_network {
char *secondary_dns;
};
+struct connman_station_info {
+ bool is_connected;
+ char *path;
+ char *type;
+ char ip[CONNMAN_STATION_STR_INFO_LEN];
+ char mac[CONNMAN_STATION_MAC_INFO_LEN];
+ char hostname[CONNMAN_STATION_STR_INFO_LEN];
+};
+
+static void destroy_station(gpointer key, gpointer value, gpointer user_data)
+{
+ struct connman_station_info *station_info;
+
+ __sync_synchronize();
+
+ station_info = value;
+
+ g_free(station_info->path);
+ g_free(station_info->type);
+ g_free(station_info);
+}
+
+int connman_technology_tethering_add_station(enum connman_service_type type,
+ const char *mac)
+{
+ const char *str_type;
+ char *lower_mac;
+ char *path;
+ struct connman_station_info *station_info;
+
+ __sync_synchronize();
+
+ DBG("type %d", type);
+
+ str_type = __connman_service_type2string(type);
+ if (str_type == NULL)
+ return 0;
+
+ path = g_strdup_printf("%s/technology/%s", CONNMAN_PATH, str_type);
+
+ station_info = g_try_new0(struct connman_station_info, 1);
+ if (station_info == NULL)
+ return -ENOMEM;
+
+ lower_mac = g_ascii_strdown(mac, -1);
+
+ memcpy(station_info->mac, lower_mac, strlen(lower_mac) + 1);
+ station_info->path = path;
+ station_info->type = g_strdup(str_type);
+
+ g_hash_table_insert(sta_hash, station_info->mac, station_info);
+
+ g_free(lower_mac);
+ return 0;
+}
+
+int connman_technology_tethering_remove_station(const char *mac)
+{
+ char *lower_mac;
+ struct connman_station_info *info_found;
+
+ __sync_synchronize();
+
+ lower_mac = g_ascii_strdown(mac, -1);
+
+ info_found = g_hash_table_lookup(sta_hash, lower_mac);
+ if (info_found == NULL)
+ return -EACCES;
+
+ g_free(lower_mac);
+ g_hash_table_remove(sta_hash, info_found->mac);
+ g_free(info_found->path);
+ g_free(info_found->type);
+ g_free(info_found);
+
+ return 0;
+}
+
const char *__connman_tethering_get_bridge(void)
{
int sk, err;
@@ -517,6 +600,9 @@ int __connman_tethering_init(void)
pn_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
NULL, remove_private_network);
+ sta_hash = g_hash_table_new_full(g_str_hash,
+ g_str_equal, NULL, NULL);
+
return 0;
}
@@ -537,5 +623,7 @@ void __connman_tethering_cleanup(void)
return;
g_hash_table_destroy(pn_hash);
+ g_hash_table_foreach(sta_hash, destroy_station, NULL);
+ g_hash_table_destroy(sta_hash);
dbus_connection_unref(connection);
}