Re: ipw srcipts for hal



I've removed some code duplication...
And in my opinion the script should return On if it founds at least one card on, and not as dan said, off if it finds at least one card off..
It is just an opinion...
Because one card on is enough to say that you have wireless on
What do you think?

----- Messaggio originale -----
Da: Dan Williams <dcbw redhat com>
A: dragoran <drago01 gmail com>
Cc: yelo_3 <yelo_3 yahoo it>; network manager <networkmanager-list gnome org>; David Zeuthen <davidz redhat com>; Bastien Nocera <bnocera redhat com>
Inviato: Lunedì 25 giugno 2007, 18:36:25
Oggetto: Re: ipw srcipts for hal

On Mon, 2007-06-25 at 18:20 +0200, dragoran wrote:
> 
> 
> On 6/25/07, Dan Williams <dcbw redhat com> wrote:
>         On Mon, 2007-06-25 at 16:09 +0200, dragoran wrote:
>         >
>         >
>         > On 6/25/07, yelo_3 <yelo_3 yahoo it> wrote:
>         >         > ok, but this does not solve the problem of
>         multiple 
>         >         killswitches (will
>         >         > show up with multiple cards) because both will
>         have
>         >         > /org/freedesktop/Hal/devices/ipw_wlan_switch as
>         uid.
>         >         Yes the previous shell script didn't solve the
>         problem... 
>         >         sorry. This might mean that the UDI should contain
>         the
>         >         interface name as you were saying
>         >         The C code misses the setrfkill section, and a !
>         =null check
>         >         when you fopen the file. 
>         >
>         > ok here is a new version.
>         > it implements setrfkill too and uses g_strdup_printf instead
>         of
>         > sprintf.
>         
>         I don't think argc == 3 is valid for the setrfkill check,
>         since the
>         number of args will still be 2...  
> 
> 
> no it should be correct
> /usr/bin/ipwWirelessCtl =1
> getrfkill = 2
> in case of setrfkill we have:
> /usr/bin/ipwWirelessCtl =1
> getrfkill = 2
> value ( 0 or 1) = 3

Oh right, sorry, I'm doing too many things at once right now.  You're
entirely correct

Dan

>  
> 
>         I'd just put a check before the
>         libhal_ctx_init() that does:
>         
>         if (argc != 2) {
>             fprintf (stderr, "Usage: ipwWirelessCtl [getrfkill]
>         [setrfkill [1|0]]\n");
>             return -1;
>         }
>         or something like that, and get rid of the argc checks for
>         getrfkill and
>         setrfkill.
>         
>         I think we should actually just reparent the device to be a
>         child of
>         Computer.  I also think the script should just rfkill
>         _everything_, and 
>         that it should return '1' if _any_ ipw radios are off.  This
>         script is
>         really only a stopgap until the _real_ kernel rfkill
>         interfaces are
>         complete, and then most these problems go away.  So instead of
>         trying to 
>         overengineer the whole thing, I think it should work like
>         this:
>         
>         a) .fdi file adds _one_ rfkill device if any ipw cards are
>         found
>         b) 'ipwWirelessCtl getrfkill' checks all ipw devices for
>         rfkill status, 
>         and if one of them is killed, it returns 1
>         c) 'ipwWirelessCtl setrfkill 1' kills _all_ ipw devices, while
>         'ipwWirelessCtl 0' re-enables _all_ ipw devices
>         
>         Sound OK?  That way we also don't have to figure out how to
>         unique-ify 
>         the device name, which the future kernel patches will handle
>         for us.
> 
> ok will update it 
> 
> 
>         I've attached an updated .fdi file for ipw devices that
>         excludes Dells,
>         and makes only _one_ killswitch device.
> 
> ok you removed the ipw3945 I will readd it and attach a new
> script/program.
> 
> 
>         Dan
>         
>         
> 






      ___________________________________ 
L'email della prossima generazione? Puoi averla con la nuova Yahoo! Mail: 
http://it.docs.yahoo.com/nowyoucan.html
#include <libhal.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <glib.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;
	int found_card_on=0;
	int error_occurred=0;

	if ( !(
		(argc==2 && strcmp("getrfkill", argv[1])==0) ||
		(argc==3 && strcmp("setrfkill", argv[1])==0 && (strcmp(argv[2], "0")==0 || strcmp(argv[2], "1"))) )
	{
		printf("usage:\n,%s getrfkill\n%s setrfkill 0\n%s setrfkill 1\n",argv[0],argv[0],argv[0]);
		return -1;
	}

	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);
		path=g_strdup_printf("/sys/class/net/%s/device/rf_kill",iface);

		if (strcmp(argv[1], "getrfkill")==0)
		{
			if ( (fd=fopen(path,"r")) != NULL )
			{
				kill_status=fgetc(fd);
				switch(kill_status)
				{
				case '0':
					found_card_on=1;
					break;
				case '1':
				case '2':
				case '3':
					break;
				default:
					error_occurred=1;
				}
			}
			else error_occurred=1;
		}
		else if (strcmp(argv[1], "setrfkill")==0)
		{
			if ( (fd=fopen(path,"rw")) != NULL )
			{
				fputc(argv[2][0],fd);
				kill_status=fgetc(fd);
				if (kill_status != argv[2][0]) error_occurred=1;
			}
			else error_occurred=1;
		}
		
		if (fd != NULL) fclose(fd);
		g_free(path);		
		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;
	}
	
	// exit with error if an error occurred
	if (error_occurred == 1) return -1;
	// exit with 0 if at least one rfkill is off (this means at least one card powered up)
	if (found_card_on == 1) return 0;
	// exit with 0 if the setrfkill operation had success
	if (strcmp("setrfkill", argv[1])==0) return 0;
	// exit with 1 if all rfkills are 1 (this means no card is powered up)
	return 0;
}


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