1 From c7d7214b511b0fa8b43f21b3b87416051fa9ef29 Mon Sep 17 00:00:00 2001
2 From: Chengyi Zhao <chengyi1.zhao@archermind.com>
3 Date: Wed, 10 Jul 2013 17:54:32 +0800
4 Subject: [PATCH 17/32] Tethering: Add station information management feature
6 Change-Id: I2f699e42ec5ce7f148b8c1d685b52ee32e2e236b
8 include/technology.h | 4 +++
9 plugins/wifi.c | 13 ++++++++
10 src/tethering.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
11 3 files changed, 104 insertions(+)
13 diff --git a/include/technology.h b/include/technology.h
14 index d7fcdde..b13d4ec 100644
15 --- a/include/technology.h
16 +++ b/include/technology.h
17 @@ -36,6 +36,10 @@ extern "C" {
19 struct connman_technology;
21 +int connman_technology_tethering_add_station(enum connman_service_type type,
23 +int connman_technology_tethering_remove_station(const char *mac);
25 void connman_technology_tethering_notify(struct connman_technology *technology,
27 int connman_technology_set_regdom(const char *alpha2);
28 diff --git a/plugins/wifi.c b/plugins/wifi.c
29 index 69a0e23..b5bc3ba 100644
32 @@ -2719,6 +2719,17 @@ static void apply_peer_services(GSupplicantPeer *peer,
36 +static void add_station(const char *mac)
38 + connman_technology_tethering_add_station(CONNMAN_SERVICE_TYPE_WIFI,
42 +static void remove_station(const char *mac)
44 + connman_technology_tethering_remove_station(mac);
47 static void peer_found(GSupplicantPeer *peer)
49 GSupplicantInterface *iface = g_supplicant_peer_get_interface(peer);
50 @@ -2887,6 +2898,8 @@ static const GSupplicantCallbacks callbacks = {
51 .network_added = network_added,
52 .network_removed = network_removed,
53 .network_changed = network_changed,
54 + .add_station = add_station,
55 + .remove_station = remove_station,
56 .peer_found = peer_found,
57 .peer_lost = peer_lost,
58 .peer_changed = peer_changed,
59 diff --git a/src/tethering.c b/src/tethering.c
60 index ceeec74..0cbf06c 100644
65 #define DEFAULT_MTU 1500
67 +#define CONNMAN_STATION_STR_INFO_LEN 64
68 +#define CONNMAN_STATION_MAC_INFO_LEN 32
70 static char *private_network_primary_dns = NULL;
71 static char *private_network_secondary_dns = NULL;
73 @@ -60,6 +63,7 @@ static GDHCPServer *tethering_dhcp_server = NULL;
74 static struct connman_ippool *dhcp_ippool = NULL;
75 static DBusConnection *connection;
76 static GHashTable *pn_hash;
77 +static GHashTable *sta_hash;
79 struct connman_private_network {
81 @@ -76,6 +80,84 @@ struct connman_private_network {
85 +struct connman_station_info {
89 + char ip[CONNMAN_STATION_STR_INFO_LEN];
90 + char mac[CONNMAN_STATION_MAC_INFO_LEN];
91 + char hostname[CONNMAN_STATION_STR_INFO_LEN];
94 +static void destroy_station(gpointer key, gpointer value, gpointer user_data)
96 + struct connman_station_info *station_info;
98 + __sync_synchronize();
100 + station_info = value;
102 + g_free(station_info->path);
103 + g_free(station_info->type);
104 + g_free(station_info);
107 +int connman_technology_tethering_add_station(enum connman_service_type type,
110 + const char *str_type;
113 + struct connman_station_info *station_info;
115 + __sync_synchronize();
117 + DBG("type %d", type);
119 + str_type = __connman_service_type2string(type);
120 + if (str_type == NULL)
123 + path = g_strdup_printf("%s/technology/%s", CONNMAN_PATH, str_type);
125 + station_info = g_try_new0(struct connman_station_info, 1);
126 + if (station_info == NULL)
129 + lower_mac = g_ascii_strdown(mac, -1);
131 + memcpy(station_info->mac, lower_mac, strlen(lower_mac) + 1);
132 + station_info->path = path;
133 + station_info->type = g_strdup(str_type);
135 + g_hash_table_insert(sta_hash, station_info->mac, station_info);
141 +int connman_technology_tethering_remove_station(const char *mac)
144 + struct connman_station_info *info_found;
146 + __sync_synchronize();
148 + lower_mac = g_ascii_strdown(mac, -1);
150 + info_found = g_hash_table_lookup(sta_hash, lower_mac);
151 + if (info_found == NULL)
155 + g_hash_table_remove(sta_hash, info_found->mac);
156 + g_free(info_found->path);
157 + g_free(info_found->type);
158 + g_free(info_found);
163 const char *__connman_tethering_get_bridge(void)
166 @@ -534,6 +616,9 @@ int __connman_tethering_init(void)
167 pn_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
168 NULL, remove_private_network);
170 + sta_hash = g_hash_table_new_full(g_str_hash,
171 + g_str_equal, NULL, NULL);
176 @@ -554,5 +639,7 @@ void __connman_tethering_cleanup(void)
179 g_hash_table_destroy(pn_hash);
180 + g_hash_table_foreach(sta_hash, destroy_station, NULL);
181 + g_hash_table_destroy(sta_hash);
182 dbus_connection_unref(connection);