6b5c0908a71a9a9d9e50c6d4ae4a8a958f986083
[scm/bb/tizen-distro.git] / meta-tizen / meta-tizen-adaptation-oe-core / recipes-connectivity / connman / connman / 0025-Tethering-Get-the-client-mac-info-of-Gadget-tether.patch
1 From 58bd810c3a61593a3c7494f843fc5dfc1d411769 Mon Sep 17 00:00:00 2001
2 From: "guoqiang.liu" <guoqiang.liu@archermind.com>
3 Date: Wed, 25 Sep 2013 16:36:21 +0800
4 Subject: [PATCH 25/32] Tethering: Get the client mac info of Gadget tether
5
6 Change-Id: Icfa6cd683c659e6728060d6201b90109c63fe56d
7 ---
8  plugins/gadget.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9  1 file changed, 87 insertions(+)
10
11 diff --git a/plugins/gadget.c b/plugins/gadget.c
12 index 97807d8..6bc37a7 100644
13 --- a/plugins/gadget.c
14 +++ b/plugins/gadget.c
15 @@ -25,6 +25,8 @@
16  
17  #include <errno.h>
18  #include <net/if.h>
19 +#include <stdio.h>
20 +#include <string.h>
21  
22  #ifndef IFF_LOWER_UP
23  #define IFF_LOWER_UP   0x10000
24 @@ -226,6 +228,71 @@ static struct connman_device_driver gadget_dev_driver = {
25  };
26  
27  static GList *cdc_interface_list = NULL;
28 +static GHashTable *cdc_mac_hash = NULL;
29 +
30 +static void add_station(int index)
31 +{
32 +       char *path, line[128] = {'\0'};
33 +       char *ifname = connman_inet_ifname(index);
34 +       char *mac;
35 +       FILE *f;
36 +
37 +       if (ifname == NULL)
38 +               return;
39 +
40 +       path = g_strdup_printf("/sys/class/usb_mode/%s/f_rndis/ethaddr",
41 +                                       ifname);
42 +
43 +       f = fopen(path, "re");
44 +
45 +       g_free(ifname);
46 +       g_free(path);
47 +
48 +       if (f == NULL)
49 +               return;
50 +
51 +       if (fgets(line, sizeof(line), f) == NULL) {
52 +               fclose(f);
53 +               return;
54 +       }
55 +
56 +       fclose(f);
57 +
58 +       mac = g_ascii_strdown(line, strlen(line) - 1);
59 +       DBG("Add station %s in Technology %d", mac,
60 +                                               CONNMAN_SERVICE_TYPE_GADGET);
61 +
62 +       g_hash_table_insert(cdc_mac_hash, GINT_TO_POINTER(index),
63 +                               mac);
64 +
65 +       connman_technology_tethering_add_station(CONNMAN_SERVICE_TYPE_GADGET,
66 +                               mac);
67 +}
68 +
69 +static void remove_station(int index)
70 +{
71 +       char *mac;
72 +       mac = g_hash_table_lookup(cdc_mac_hash, GINT_TO_POINTER(index));
73 +       if (mac == NULL)
74 +               return;
75 +
76 +       connman_technology_tethering_remove_station(mac);
77 +
78 +       g_hash_table_remove(cdc_mac_hash, GINT_TO_POINTER(index));
79 +}
80 +
81 +static gboolean remove_all_station(gpointer key, gpointer value, gpointer user_data)
82 +{
83 +       char *mac;
84 +       mac = value;
85 +       if (mac == NULL)
86 +               return TRUE;
87 +
88 +       connman_technology_tethering_remove_station(mac);
89 +
90 +       return TRUE;
91 +}
92 +
93  
94  static void gadget_tech_add_interface(struct connman_technology *technology,
95                         int index, const char *name, const char *ident)
96 @@ -246,6 +313,8 @@ static void gadget_tech_remove_interface(struct connman_technology *technology,
97  
98         cdc_interface_list = g_list_remove(cdc_interface_list,
99                                         GINT_TO_POINTER((int) index));
100 +
101 +       remove_station(index);
102  }
103  
104  static void gadget_tech_enable_tethering(struct connman_technology *technology,
105 @@ -270,6 +339,8 @@ static void gadget_tech_enable_tethering(struct connman_technology *technology,
106                 connman_inet_ifup(index);
107  
108                 connman_inet_add_to_bridge(index, bridge);
109 +
110 +               add_station(index);
111         }
112  }
113  
114 @@ -283,6 +354,8 @@ static void gadget_tech_disable_tethering(struct connman_technology *technology,
115  
116                 connman_inet_remove_from_bridge(index, bridge);
117  
118 +               remove_station(index);
119 +
120                 connman_inet_ifdown(index);
121  
122                 connman_technology_tethering_notify(technology, false);
123 @@ -305,14 +378,28 @@ static int gadget_tech_set_tethering(struct connman_technology *technology,
124  
125  static int gadget_tech_probe(struct connman_technology *technology)
126  {
127 +       DBG("tech probe %p", technology);
128 +
129 +       cdc_mac_hash = g_hash_table_new_full(g_direct_hash,
130 +                                        g_direct_equal, NULL, g_free);
131 +
132         return 0;
133  }
134  
135  static void gadget_tech_remove(struct connman_technology *technology)
136  {
137 +       DBG("tech remove %p", technology);
138 +
139         g_list_free(cdc_interface_list);
140  
141         cdc_interface_list = NULL;
142 +
143 +       if (cdc_mac_hash) {
144 +               g_hash_table_foreach_remove(cdc_mac_hash, remove_all_station,
145 +                                               NULL);
146 +               g_hash_table_destroy(cdc_mac_hash);
147 +               cdc_mac_hash = NULL;
148 +       }
149  }
150  
151  static struct connman_technology_driver gadget_tech_driver = {
152 -- 
153 1.8.1.4
154