Ticket #242: neod_dynamicwifiinterface_and_useoftempdaemontotogglewifi.diff
| File neod_dynamicwifiinterface_and_useoftempdaemontotogglewifi.diff, 6.5 KB (added by prahal, 3 years ago) |
|---|
-
configure.ac
18 18 AC_SUBST(GETTEXT_PACKAGE) 19 19 AM_GLIB_GNU_GETTEXT 20 20 21 PKG_CHECK_MODULES(NEOD, gtk+-2.0 gthread-2.0 gconf-2.0 libh1settings libnotify )21 PKG_CHECK_MODULES(NEOD, gtk+-2.0 gthread-2.0 gconf-2.0 libh1settings libnotify dbus-glib-1) 22 22 23 AC_MSG_CHECKING([for wireless-tools >= 28pre9]) 24 AC_TRY_COMPILE([#include <iwlib.h>], 25 [#ifndef IWEVGENIE 26 #error "not found" 27 #endif], 28 [ac_have_iwevgenie=yes], 29 [ac_have_iwevgenie=no]) 30 AC_MSG_RESULT($ac_have_iwevgenie) 31 if test "$ac_have_iwevgenie" = no; then 32 AC_MSG_ERROR(wireless-tools >= 28pre9 not installed or not functional) 33 fi 34 IWLIB=-liw 35 AC_SUBST(IWLIB) 36 37 23 38 AC_ARG_WITH([platform], 24 39 AC_HELP_STRING([--with-platform], [Which platform to use [[default=vanilla]]]), 25 40 [neod_platform=$with_platform]) -
src/wifi.c
14 14 15 15 16 16 #include "wifi.h" 17 #include <dbus/dbus-glib.h> 17 18 18 gboolean 19 wifi_radio_is_on (const gchar *iface) 19 static gchar * found_ifname = NULL; 20 21 static int 22 get_ifwireless(int skfd, 23 char * ifname, 24 struct wireless_info * info) 20 25 { 21 struct iwreq wrq; 26 27 memset((char *) info, 0, sizeof(struct wireless_info)); 28 29 /* Get basic information */ 30 if(iw_get_basic_config(skfd, ifname, &(info->b)) < 0) 31 { 32 /* If no wireless name : no wireless extensions */ 33 /* But let's check if the interface exists at all */ 34 struct ifreq ifr; 35 36 strncpy(ifr.ifr_name, ifname, IFNAMSIZ); 37 if(ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) 38 return(-ENODEV); 39 else 40 return(-ENOTSUP); 41 } 42 43 return 0; 44 } 45 46 static int 47 fill_wireless(int skfd, 48 char * ifname, 49 char * args[], 50 int count) 51 { 52 struct wireless_info info; 53 int rc; 54 55 rc = get_ifwireless(skfd, ifname, &info); 56 if (!rc) { 57 if (found_ifname == NULL) 58 found_ifname = g_strdup(ifname); 59 } 60 return rc; 61 } 62 63 64 65 gchar * 66 wifi_first_interface () 67 { 22 68 int sock = 0; /* socket */ 23 69 24 70 /* Open socket to perform ioctl() on */ … … 29 75 return FALSE; 30 76 } 31 77 32 /* Clear our request and set the interface name */ 33 memset (&wrq, 0, sizeof (struct iwreq)); 34 strncpy ((char *)&wrq.ifr_name, iface, IFNAMSIZ); 35 36 /* Feel the power, uhh, do the ioctl() */ 37 if (ioctl (sock, SIOCGIWTXPOW, &wrq) != 0) 78 if(found_ifname == NULL) 79 iw_enum_devices(sock, &fill_wireless ,NULL, 0); 80 if(found_ifname == NULL) 38 81 { 39 g_warning ("Error performing ioctl: %s", g_strerror (errno)); 40 close (sock); 82 g_warning ("No wireless interface found."); 41 83 return FALSE; 42 84 } 43 85 44 86 close (sock); 45 87 46 return !wrq.u.txpower.disabled;88 return g_strdup(found_ifname); 47 89 } 48 90 49 91 gboolean 50 wifi_radio_ control (const gchar *iface, gboolean enable)92 wifi_radio_is_on (const gchar *iface) 51 93 { 52 94 struct iwreq wrq; 53 95 int sock = 0; /* socket */ … … 62 104 63 105 /* Clear our request and set the interface name */ 64 106 memset (&wrq, 0, sizeof (struct iwreq)); 65 66 107 strncpy ((char *)&wrq.ifr_name, iface, IFNAMSIZ); 67 108 68 109 /* Feel the power, uhh, do the ioctl() */ … … 73 114 return FALSE; 74 115 } 75 116 76 wrq.u.txpower.disabled = !enable;117 close (sock); 77 118 78 /* Feel the power, uhh, do the ioctl() */ 79 if (ioctl (sock, SIOCSIWTXPOW, &wrq) != 0) 119 return !wrq.u.txpower.disabled; 120 } 121 122 gboolean 123 wifi_radio_control (const gchar *iface, gboolean enable) 124 { 125 DBusGProxy *proxy; 126 DBusGConnection *connection; 127 GError *error = NULL; 128 gboolean result; 129 130 connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); 131 if (connection == NULL) 80 132 { 81 g_warning ("Error performing ioctl: %s", g_strerror (errno)); 82 close (sock); 83 return FALSE; 133 g_warning("Unable to connect to dbus: %sn", error->message); 134 g_error_free (error); 135 /* Basically here, there is a problem, since there is no dbus :) */ 136 return FALSE; 84 137 } 85 138 86 close (sock); 139 /* This won't trigger activation! */ 140 proxy = dbus_g_proxy_new_for_name (connection, 141 "org.prahal.TempDaemon", 142 "/org/prahal/TempDaemon/Wifi", 143 "org.prahal.TempDaemon.Wifi"); 87 144 88 return TRUE; 145 /* The method call will trigger activation, more on that later */ 146 if (!dbus_g_proxy_call (proxy, "WifiRadioControl", &error, G_TYPE_STRING, iface, G_TYPE_BOOLEAN, enable, G_TYPE_INVALID, 147 G_TYPE_BOOLEAN, &result, G_TYPE_INVALID)) 148 { 149 /* Method failed, the GError is set, let's warn everyone */ 150 g_warning ("Woops remote method failed: %s", error->message); 151 g_error_free (error); 152 return FALSE; 153 } 154 155 g_print ("We got the folowing result: %d", result); 156 157 /* Cleanup */ 158 g_object_unref (proxy); 159 160 return result; 89 161 } -
src/neod-device.c
87 87 #define HEADPHONE_INSERTION_SWITCHCODE 0x02 88 88 #define CHARGER_INSERTION_BUTTON 0x164 89 89 90 #define WIFI_IFACE "eth1"91 92 90 #define BIT_MASK( name, numbits ) \ 93 91 unsigned short name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ]; \ 94 92 memset( name, 0, sizeof( name ) ) … … 240 238 void 241 239 device_wifi_enable(gboolean enable) 242 240 { 243 wifi_radio_control( WIFI_IFACE, enable);241 wifi_radio_control(wifi_first_interface(), enable); 244 242 } 245 243 246 244 gboolean 247 245 device_wifi_is_enabled() 248 246 { 249 return wifi_radio_is_on ( WIFI_IFACE);247 return wifi_radio_is_on ( wifi_first_interface() ); 250 248 } 251 249 252 250 void -
src/wifi.h
25 25 #include <netdb.h> 26 26 #include <unistd.h> 27 27 28 #include <linux/if.h> 29 #include <linux/wireless.h> 28 #include <iwlib.h> 30 29 30 gchar *wifi_first_interface (); 31 31 gboolean wifi_radio_is_on (const gchar *iface); 32 32 gboolean wifi_radio_control (const gchar *iface, gboolean enable); 33 33 #endif /* __WIFI_H_ */ -
src/Makefile.am
25 25 wifi.c \ 26 26 wifi.h 27 27 28 neod_LDADD = @NEOD_LIBS@ -lapm28 neod_LDADD = @NEOD_LIBS@ @IWLIB@ -lapm 29 29 30 30 MAINTAINERCLEANFILES = config.h.in Makefile.in 31 31
