meta-tizen: connman: move recipe and patches to the proper dir
[scm/bb/tizen-distro.git] / meta-tizen / meta-tizen-adaptation / meta / recipes-connectivity / connman / connman / 0017-Tethering-Add-station-information-management-feature.patch
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
5
6 Change-Id: I2f699e42ec5ce7f148b8c1d685b52ee32e2e236b
7 ---
8  include/technology.h |  4 +++
9  plugins/wifi.c       | 13 ++++++++
10  src/tethering.c      | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++
11  3 files changed, 104 insertions(+)
12
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" {
18  
19  struct connman_technology;
20  
21 +int connman_technology_tethering_add_station(enum connman_service_type type,
22 +                                             const char *mac);
23 +int connman_technology_tethering_remove_station(const char *mac);
24 +
25  void connman_technology_tethering_notify(struct connman_technology *technology,
26                                                         bool enabled);
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
30 --- a/plugins/wifi.c
31 +++ b/plugins/wifi.c
32 @@ -2719,6 +2719,17 @@ static void apply_peer_services(GSupplicantPeer *peer,
33         }
34  }
35  
36 +static void add_station(const char *mac)
37 +{
38 +       connman_technology_tethering_add_station(CONNMAN_SERVICE_TYPE_WIFI,
39 +                                                mac);
40 +}
41 +
42 +static void remove_station(const char *mac)
43 +{
44 +       connman_technology_tethering_remove_station(mac);
45 +}
46 +
47  static void peer_found(GSupplicantPeer *peer)
48  {
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
61 --- a/src/tethering.c
62 +++ b/src/tethering.c
63 @@ -52,6 +52,9 @@
64  
65  #define DEFAULT_MTU    1500
66  
67 +#define CONNMAN_STATION_STR_INFO_LEN           64
68 +#define CONNMAN_STATION_MAC_INFO_LEN           32
69 +
70  static char *private_network_primary_dns = NULL;
71  static char *private_network_secondary_dns = NULL;
72  
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;
78  
79  struct connman_private_network {
80         char *owner;
81 @@ -76,6 +80,84 @@ struct connman_private_network {
82         char *secondary_dns;
83  };
84  
85 +struct connman_station_info {
86 +       bool is_connected;
87 +       char *path;
88 +       char *type;
89 +       char ip[CONNMAN_STATION_STR_INFO_LEN];
90 +       char mac[CONNMAN_STATION_MAC_INFO_LEN];
91 +       char hostname[CONNMAN_STATION_STR_INFO_LEN];
92 +};
93 +
94 +static void destroy_station(gpointer key, gpointer value, gpointer user_data)
95 +{
96 +       struct connman_station_info *station_info;
97 +
98 +       __sync_synchronize();
99 +
100 +       station_info = value;
101 +
102 +       g_free(station_info->path);
103 +       g_free(station_info->type);
104 +       g_free(station_info);
105 +}
106 +
107 +int connman_technology_tethering_add_station(enum connman_service_type type,
108 +                                                       const char *mac)
109 +{
110 +       const char *str_type;
111 +       char *lower_mac;
112 +       char *path;
113 +       struct connman_station_info *station_info;
114 +
115 +       __sync_synchronize();
116 +
117 +       DBG("type %d", type);
118 +
119 +       str_type = __connman_service_type2string(type);
120 +       if (str_type == NULL)
121 +               return 0;
122 +
123 +       path = g_strdup_printf("%s/technology/%s", CONNMAN_PATH, str_type);
124 +
125 +       station_info = g_try_new0(struct connman_station_info, 1);
126 +       if (station_info == NULL)
127 +               return -ENOMEM;
128 +
129 +       lower_mac = g_ascii_strdown(mac, -1);
130 +
131 +       memcpy(station_info->mac, lower_mac, strlen(lower_mac) + 1);
132 +       station_info->path = path;
133 +       station_info->type = g_strdup(str_type);
134 +
135 +       g_hash_table_insert(sta_hash, station_info->mac, station_info);
136 +
137 +       g_free(lower_mac);
138 +       return 0;
139 +}
140 +
141 +int connman_technology_tethering_remove_station(const char *mac)
142 +{
143 +       char *lower_mac;
144 +       struct connman_station_info *info_found;
145 +
146 +       __sync_synchronize();
147 +
148 +       lower_mac = g_ascii_strdown(mac, -1);
149 +
150 +       info_found = g_hash_table_lookup(sta_hash, lower_mac);
151 +       if (info_found == NULL)
152 +               return -EACCES;
153 +
154 +       g_free(lower_mac);
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);
159 +
160 +       return 0;
161 +}
162 +
163  const char *__connman_tethering_get_bridge(void)
164  {
165         int sk, err;
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);
169  
170 +       sta_hash = g_hash_table_new_full(g_str_hash,
171 +                                        g_str_equal, NULL, NULL);
172 +
173         return 0;
174  }
175  
176 @@ -554,5 +639,7 @@ void __connman_tethering_cleanup(void)
177                 return;
178  
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);
183  }
184 -- 
185 1.8.1.4
186