Hi people,

the attached patch adds an indicator sensor to wpi devices that describes the
current RFKill status.  If the RF killswitch is engaged, the sensor reads "Off",
if it is not engaged and the device can operate, it reads "On".

If this is okay, I plan on adding similar sensors to other wireless devices,
but in that case I'd need help testing those because I only have access to wpi
devices.

-- 
    Gregor Best
Index: dev/pci/if_wpi.c
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_wpi.c,v
retrieving revision 1.110
diff -u -r1.110 if_wpi.c
--- dev/pci/if_wpi.c    2 Jun 2011 18:36:53 -0000       1.110
+++ dev/pci/if_wpi.c    22 May 2012 18:17:02 -0000
@@ -33,6 +33,9 @@
 #include <sys/conf.h>
 #include <sys/device.h>
 #include <sys/workq.h>
+#ifndef SMALL_KERNEL
+#include <sys/sensors.h>
+#endif
 
 #include <machine/bus.h>
 #include <machine/endian.h>
@@ -149,6 +152,9 @@
 int            wpi_init(struct ifnet *);
 void           wpi_stop(struct ifnet *, int);
 
+#ifndef SMALL_KERNEL
+void wpi_sensor_refresh(void *);
+#endif
 #ifdef WPI_DEBUG
 #define DPRINTF(x)     do { if (wpi_debug > 0) printf x; } while (0)
 #define DPRINTFN(n, x) do { if (wpi_debug >= (n)) printf x; } while (0)
@@ -326,6 +332,19 @@
        wpi_radiotap_attach(sc);
 #endif
        timeout_set(&sc->calib_to, wpi_calib_timeout, sc);
+
+#ifndef SMALL_KERNEL
+       strlcpy(sc->sc_sensor.desc, "Radio enabled", sizeof("Radio enabled"));
+       sc->sc_sensor.type = SENSOR_INDICATOR;
+       sc->sc_sensor.status = SENSOR_S_UNSPEC;
+
+       strlcpy(sc->sc_sensordev.xname, sc->sc_dev.dv_xname, 
sizeof(sc->sc_sensordev.xname));
+       sensordev_install(&sc->sc_sensordev);
+       sensor_attach(&sc->sc_sensordev, &sc->sc_sensor);
+       if (sc->sc_sensor_task == NULL)
+               sc->sc_sensor_task = sensor_task_register(sc, 
wpi_sensor_refresh, 10);
+#endif
+
        return;
 
        /* Free allocated memory if something failed during attachment. */
@@ -380,6 +399,12 @@
        ieee80211_ifdetach(ifp);
        if_detach(ifp);
 
+#ifndef SMALL_KERNEL
+       sensor_detach(&sc->sc_sensordev, &sc->sc_sensor);
+       if (sc->sc_sensor_task != NULL)
+               sensor_task_unregister(sc->sc_sensor_task);
+       sensordev_deinstall(&sc->sc_sensordev);
+#endif
        return 0;
 }
 
@@ -489,6 +514,15 @@
        for (; count > 0; count--, data++, addr += 4)
                wpi_prph_write(sc, addr, *data);
 }
+
+#ifndef SMALL_KERNEL
+void
+wpi_sensor_refresh(void *arg)
+{
+       struct wpi_softc *sc = arg;
+       sc->sc_sensor.value = wpi_prph_read(sc, WPI_APMG_RFKILL) & 1;
+}
+#endif
 
 static __inline uint32_t
 wpi_mem_read(struct wpi_softc *sc, uint32_t addr)
Index: dev/pci/if_wpivar.h
===================================================================
RCS file: /cvs/src/sys/dev/pci/if_wpivar.h,v
retrieving revision 1.23
diff -u -r1.23 if_wpivar.h
--- dev/pci/if_wpivar.h 7 Sep 2010 16:21:45 -0000       1.23
+++ dev/pci/if_wpivar.h 22 May 2012 18:17:02 -0000
@@ -199,4 +199,7 @@
 #define sc_txtap       sc_txtapu.th
        int                     sc_txtap_len;
 #endif
+       struct ksensor sc_sensor;
+       struct ksensordev sc_sensordev;
+       struct sensor_task *sc_sensor_task;
 };

Attachment: pgpK1IowLaEFV.pgp
Description: PGP signature

Reply via email to