On Wed, May 23, 2012 at 09:12:20AM +0200, Tobias Ulmer wrote:
> [...]
> This a read-only sensor, it has no effect on misbehaving
> hardware as far as I can tell.
> [...]

That is right. If I recall correctly, the very reason for introducing real 
hardware killswitches was so that the OS could not
interfere with and override the kill switch in case the device needs to operate 
in RF-sensitive environments.

> [...]
> Gregor: try adding '-p' to cvs diff
> [...]

Thanks for the hint. An updated patch is attached.

-- 
    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 -p -r1.110 if_wpi.c
--- dev/pci/if_wpi.c    2 Jun 2011 18:36:53 -0000       1.110
+++ dev/pci/if_wpi.c    23 May 2012 15:17:34 -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 @@ void                wpi_hw_stop(struct wpi_softc *);
 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_attach(struct device *parent, struct
        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 @@ wpi_detach(struct device *self, int flag
        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 @@ wpi_prph_write_region_4(struct wpi_softc
        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 -p -r1.23 if_wpivar.h
--- dev/pci/if_wpivar.h 7 Sep 2010 16:21:45 -0000       1.23
+++ dev/pci/if_wpivar.h 23 May 2012 15:17:35 -0000
@@ -199,4 +199,7 @@ struct wpi_softc {
 #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;
 };

Reply via email to