Re: ipw srcipts for hal



here is a C implementation of the ipwWirelessCtl
the udi is hardcoded and I only implemented get for now (will add the rest tomorrow). It also uses all values from the README.
yelo_3 you have a typo in your patch (you used getrfkill instead of set ;) )

Bastien: the UDI that will get passed to the script would be that of the killswitch corret?

programm is attached... any comments?
#include <libhal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static LibHalContext *hal_ctx;

int main(int argc,char** argv) {

	DBusError error;

	char *udi="/org/freedesktop/Hal/devices/ipw_wlan_switch";
	char *parent;
	char *iface;
	int i;
	char kill_status;
	char **udis;
	int num_udis;
	FILE *fd;
	char path[40];

	dbus_error_init (&error);

	if ((hal_ctx = libhal_ctx_new ()) == NULL) {
		fprintf (stderr, "error: libhal_ctx_new\n");
		return -1;
	}

	if (!libhal_ctx_set_dbus_connection (hal_ctx, dbus_bus_get (DBUS_BUS_SYSTEM, &error))) {
		fprintf (stderr, "error: libhal_ctx_set_dbus_connection: %s: %s\n", error.name, error.message);
		LIBHAL_FREE_DBUS_ERROR (&error);
		return -1;
	}

	if (!libhal_ctx_init (hal_ctx, &error)) {
		fprintf (stderr, "error: libhal_ctx_init: %s: %s\n", error.name, error.message);
		LIBHAL_FREE_DBUS_ERROR (&error);
		return -1;
	}


	parent = libhal_device_get_property_string (hal_ctx, udi, "info.parent", &error);
	udis = libhal_manager_find_device_string_match (hal_ctx, "info.parent", parent, &num_udis, &error);
	libhal_free_string(parent);

	
	for (i = 0; i < num_udis; i++) {
		if(strcmp(udis[i],udi)==0) continue;
		iface = libhal_device_get_property_string (hal_ctx, udis[i], "net.interface", &error);
		sprintf(path,"/sys/class/net/%s/device/rf_kill",iface);
		fd=fopen(path,"r");
		kill_status=fgetc(fd);
		fclose(fd);
		switch(kill_status) {
			case '0':
				return 1;
			break;
			case '1':
			case '2':
			case '3':
				return 0;
			break;
		}
		libhal_free_string(iface);
	}

	libhal_free_string_array (udis);
	
	
	if (dbus_error_is_set (&error)) {
		fprintf (stderr, "error: %s: %s\n", error.name, error.message);
		dbus_error_free (&error);
		return -1;
	}

	return -1;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]