r4324 - trunk/src/target/OM-2007.2/daemons/neod/src

rob at sita.openmoko.org rob at sita.openmoko.org
Tue Apr 8 14:03:57 CEST 2008


Author: rob
Date: 2008-04-08 14:03:56 +0200 (Tue, 08 Apr 2008)
New Revision: 4324

Added:
   trunk/src/target/OM-2007.2/daemons/neod/src/wifi.c
   trunk/src/target/OM-2007.2/daemons/neod/src/wifi.h
Modified:
   trunk/src/target/OM-2007.2/daemons/neod/src/Makefile.am
   trunk/src/target/OM-2007.2/daemons/neod/src/buttonactions.c
Log:
Add Wifi control options to the power menu.
Hook up the peripheral control options to the function that actually makes the
changes.


Modified: trunk/src/target/OM-2007.2/daemons/neod/src/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/daemons/neod/src/Makefile.am	2008-04-08 10:19:34 UTC (rev 4323)
+++ trunk/src/target/OM-2007.2/daemons/neod/src/Makefile.am	2008-04-08 12:03:56 UTC (rev 4324)
@@ -10,7 +10,9 @@
 
 neod_SOURCES = \
   buttonactions.c \
-  neod-main.c
+  neod-main.c \
+  wifi.c \
+  wifi.h
 
 neod_LDADD = @NEOD_LIBS@ -lapm
 

Modified: trunk/src/target/OM-2007.2/daemons/neod/src/buttonactions.c
===================================================================
--- trunk/src/target/OM-2007.2/daemons/neod/src/buttonactions.c	2008-04-08 10:19:34 UTC (rev 4323)
+++ trunk/src/target/OM-2007.2/daemons/neod/src/buttonactions.c	2008-04-08 12:03:56 UTC (rev 4324)
@@ -15,6 +15,8 @@
  */
 #include "buttonactions.h"
 
+#include "wifi.h"
+
 #include <gconf/gconf-client.h>
 
 #include <gtk/gtk.h>
@@ -75,6 +77,8 @@
 #define HEADPHONE_INSERTION_SWITCHCODE 0x02
 #define CHARGER_INSERTION_BUTTON 0x164
 
+#define WIFI_IFACE "eth0"
+
 #define BIT_MASK( name, numbits )                                        \
     unsigned short  name[ ((numbits) - 1) / (sizeof( short ) * 8) + 1 ];    \
     memset( name, 0, sizeof( name ) )
@@ -106,6 +110,7 @@
     GSM = 0,
     BLUETOOTH = 1,
     GPS = 2,
+    WIFI = 3,
 };
 
 enum PowerManagementMode
@@ -652,6 +657,8 @@
             return read_boolean_from_path( "/sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/gta01-pm-gps.0/pwron" );
 #endif
             return FALSE;
+        case WIFI:
+            return wifi_radio_is_on ( WIFI_IFACE );
         default:
             g_assert( FALSE ); // should never reach this
     }
@@ -677,6 +684,9 @@
             write_boolean_to_path( "/sys/devices/platform/s3c2410-i2c/i2c-adapter/i2c-0/0-0008/gta01-pm-gps.0/power_on", on );
 #endif
             break;
+        case WIFI:
+            wifi_radio_control ( WIFI_IFACE, on );
+            break;
         default:
             g_assert( FALSE ); // should never reach this
     }
@@ -685,9 +695,9 @@
 void neod_buttonactions_popup_selected_switch_power( GtkWidget* button, gpointer user_data )
 {
     gtk_widget_hide( power_menu );
-    gboolean new_power_state = !is_turned_on( (int)user_data );
-    g_debug( "switch power of unit %d to %d", (int)user_data, (int)new_power_state );
-    //FIXME implement this and notify user
+    gboolean new_power_state = !is_turned_on( GPOINTER_TO_INT( user_data ) );
+    g_debug( "switch power of unit %d to %d", GPOINTER_TO_INT( user_data ), new_power_state );
+    peripheral_set_power ( GPOINTER_TO_INT( user_data ), new_power_state);
 }
 
 void neod_buttonactions_gconf_cb( GConfClient *client, guint cnxn_id, GConfEntry *entry, gpointer data )
@@ -751,6 +761,7 @@
     static GtkWidget* gsmpower = 0;
     static GtkWidget* btpower = 0;
     static GtkWidget* gpspower = 0;
+    static GtkWidget* wifipower = 0;
     static GtkWidget* pmprofile = 0;
 
     // remember last active window before showing popup menu
@@ -773,17 +784,21 @@
 //        gtk_box_pack_start_defaults( GTK_BOX(box), title );
 
         gsmpower = gtk_button_new();
-        g_signal_connect( G_OBJECT(gsmpower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), (void*)GSM );
+        g_signal_connect( G_OBJECT(gsmpower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), GINT_TO_POINTER( GSM ) );
         gtk_box_pack_start_defaults( GTK_BOX(box), gsmpower );
 
         btpower = gtk_button_new();
-        g_signal_connect( G_OBJECT(btpower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), (void*)BLUETOOTH );
+        g_signal_connect( G_OBJECT(btpower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), GINT_TO_POINTER( BLUETOOTH ) );
         gtk_box_pack_start_defaults( GTK_BOX(box), btpower );
 
         gpspower = gtk_button_new();
-        g_signal_connect( G_OBJECT(gpspower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), (void*)GPS );
+        g_signal_connect( G_OBJECT(gpspower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), GINT_TO_POINTER( GPS ) );
         gtk_box_pack_start_defaults( GTK_BOX(box), gpspower );
 
+        wifipower = gtk_button_new();
+        g_signal_connect( G_OBJECT(wifipower), "clicked", G_CALLBACK(neod_buttonactions_popup_selected_switch_power), GINT_TO_POINTER( WIFI ) );
+        gtk_box_pack_start_defaults( GTK_BOX(box), wifipower );
+
         gtk_box_pack_start_defaults( GTK_BOX(box), gtk_hseparator_new() );
 
         pmprofile = gtk_combo_box_new_text();
@@ -821,6 +836,8 @@
     gtk_button_set_label( GTK_BUTTON(gsmpower), g_strdup_printf( "Turn %s GSM", is_turned_on( GSM ) ? "off" : "on" ) );
     gtk_button_set_label( GTK_BUTTON(btpower), g_strdup_printf( "Turn %s Bluetooth", is_turned_on( BLUETOOTH ) ? "off" : "on" ) );
     gtk_button_set_label( GTK_BUTTON(gpspower), g_strdup_printf( "Turn %s GPS", is_turned_on( GPS ) ? "off" : "on" ) );
+    gtk_button_set_label( GTK_BUTTON(wifipower), g_strdup_printf( "Turn %s Wifi", is_turned_on( WIFI ) ? "off" : "on" ) );
+
     int response = gtk_dialog_run( GTK_DIALOG(power_menu) );
     g_debug( "gtk_dialog_run completed, response = %d", response );
 }

Added: trunk/src/target/OM-2007.2/daemons/neod/src/wifi.c
===================================================================
--- trunk/src/target/OM-2007.2/daemons/neod/src/wifi.c	2008-04-08 10:19:34 UTC (rev 4323)
+++ trunk/src/target/OM-2007.2/daemons/neod/src/wifi.c	2008-04-08 12:03:56 UTC (rev 4324)
@@ -0,0 +1,89 @@
+/*
+ *  Authored by Rob Bradford <rob at o-hand.com>
+ *  Copyright (C) 2008 OpenMoko, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Public License for more details.
+ */
+
+
+#include "wifi.h"
+
+gboolean
+wifi_radio_is_on (const gchar *iface)
+{
+  struct iwreq wrq;
+  int sock = 0; /* socket */
+
+  /* Open socket to perform ioctl() on */
+  sock = socket (AF_INET, SOCK_DGRAM, 0);
+  if (!sock)
+  {
+    g_warning ("Unable to open socket: %s", g_strerror (errno));
+    return FALSE;
+  }
+
+  /* Clear our request and set the interface name */
+  memset (&wrq, 0, sizeof (struct iwreq));
+  strncpy ((char *)&wrq.ifr_name, iface, IFNAMSIZ);
+
+  /* Feel the power, uhh, do the ioctl() */
+  if (ioctl (sock, SIOCGIWTXPOW, &wrq) != 0)
+  {
+    g_warning ("Error performing ioctl: %s", g_strerror (errno));
+    close (sock);
+    return FALSE;
+  }
+
+  close (sock);
+
+  return !wrq.u.txpower.disabled;
+}
+
+gboolean
+wifi_radio_control (const gchar *iface, gboolean enable)
+{
+  struct iwreq wrq;
+  int sock = 0; /* socket */
+
+  /* Open socket to perform ioctl() on */
+  sock = socket (AF_INET, SOCK_DGRAM, 0);
+  if (!sock)
+  {
+    g_warning ("Unable to open socket: %s", g_strerror (errno));
+    return FALSE;
+  }
+
+  /* Clear our request and set the interface name */
+  memset (&wrq, 0, sizeof (struct iwreq));
+
+  strncpy ((char *)&wrq.ifr_name, iface, IFNAMSIZ);
+
+  /* Feel the power, uhh, do the ioctl() */
+  if (ioctl (sock, SIOCGIWTXPOW, &wrq) != 0)
+  {
+    g_warning ("Error performing ioctl: %s", g_strerror (errno));
+    close (sock);
+    return FALSE;
+  }
+
+  wrq.u.txpower.disabled = !enable;
+
+  /* Feel the power, uhh, do the ioctl() */
+  if (ioctl (sock, SIOCSIWTXPOW, &wrq) != 0)
+  {
+    g_warning ("Error performing ioctl: %s", g_strerror (errno));
+    close (sock);
+    return FALSE;
+  }
+
+  close (sock);
+
+  return TRUE;
+}

Added: trunk/src/target/OM-2007.2/daemons/neod/src/wifi.h
===================================================================
--- trunk/src/target/OM-2007.2/daemons/neod/src/wifi.h	2008-04-08 10:19:34 UTC (rev 4323)
+++ trunk/src/target/OM-2007.2/daemons/neod/src/wifi.h	2008-04-08 12:03:56 UTC (rev 4324)
@@ -0,0 +1,34 @@
+/*
+ *  Authored by Rob Bradford <rob at o-hand.com>
+ *  Copyright (C) 2008 OpenMoko, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Public License as published by
+ *  the Free Software Foundation; version 2 of the license.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Public License for more details.
+ */
+
+#ifndef __WIFI_H_
+#define __WIFI_H_
+
+#include <glib.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include <linux/if.h>
+#include <linux/wireless.h>
+
+gboolean wifi_radio_is_on (const gchar *iface);
+gboolean wifi_radio_control (const gchar *iface, gboolean enable);
+#endif /* __WIFI_H_ */
+





More information about the commitlog mailing list