From: Samuel O. <sa...@so...> - 2007-03-14 20:23:58
|
This is a split of: "[PATCH 1/6] IrDA: IrNET code indentation" for fitting with netdev mail size limit. The IrNET code was not exactly following the kernel coding style... No functional changes, just an indentation fix. Signed-off-by: Samuel Ortiz <sa...@so...> --- net/irda/irnet/irnet.h | 189 ++-- net/irda/irnet/irnet_irda.h | 162 +-- net/irda/irnet/irnet_ppp.c | 1658 ++++++++++++++-------------- net/irda/irnet/irnet_ppp.h | 86 +- 5 files changed, 2262 insertions(+), 2405 deletions(-) diff --git a/net/irda/irnet/irnet.h b/net/irda/irnet/irnet.h index 873ae18..44b58a6 100644 --- a/net/irda/irnet/irnet.h +++ b/net/irda/irnet/irnet.h @@ -394,109 +394,105 @@ * to be called "self", and if it is borrowed from the PPP driver it is * "ap". Apart from that, it's exactly the same structure ;-) */ -typedef struct irnet_socket -{ - /* ------------------- Instance management ------------------- */ - /* We manage a linked list of IrNET socket instances */ - irda_queue_t q; /* Must be first - for hasbin */ - int magic; /* Paranoia */ - - /* --------------------- FileSystem part --------------------- */ - /* "pppd" interact directly with us on a /dev/ file */ - struct file * file; /* File descriptor of this instance */ - /* TTY stuff - to keep "pppd" happy */ - struct termios termios; /* Various tty flags */ - /* Stuff for the control channel */ - int event_index; /* Last read in the event log */ - - /* ------------------------- PPP part ------------------------- */ - /* We interface directly to the ppp_generic driver in the kernel */ - int ppp_open; /* registered with ppp_generic */ - struct ppp_channel chan; /* Interface to generic ppp layer */ - - int mru; /* Max size of PPP payload */ - u32 xaccm[8]; /* Asynchronous character map (just */ - u32 raccm; /* to please pppd - dummy) */ - unsigned int flags; /* PPP flags (compression, ...) */ - unsigned int rbits; /* Unused receive flags ??? */ - - /* ------------------------ IrTTP part ------------------------ */ - /* We create a pseudo "socket" over the IrDA tranport */ - unsigned long ttp_open; /* Set when IrTTP is ready */ - unsigned long ttp_connect; /* Set when IrTTP is connecting */ - struct tsap_cb * tsap; /* IrTTP instance (the connection) */ - - char rname[NICKNAME_MAX_LEN + 1]; - /* IrDA nickname of destination */ - __u32 rdaddr; /* Requested peer IrDA address */ - __u32 rsaddr; /* Requested local IrDA address */ - __u32 daddr; /* actual peer IrDA address */ - __u32 saddr; /* my local IrDA address */ - __u8 dtsap_sel; /* Remote TSAP selector */ - __u8 stsap_sel; /* Local TSAP selector */ - - __u32 max_sdu_size_rx;/* Socket parameters used for IrTTP */ - __u32 max_sdu_size_tx; - __u32 max_data_size; - __u8 max_header_size; - LOCAL_FLOW tx_flow; /* State of the Tx path in IrTTP */ - - /* ------------------- IrLMP and IrIAS part ------------------- */ - /* Used for IrDA Discovery and socket name resolution */ - void * ckey; /* IrLMP client handle */ - __u16 mask; /* Hint bits mask (filter discov.)*/ - int nslots; /* Number of slots for discovery */ - - struct iriap_cb * iriap; /* Used to query remote IAS */ - int errno; /* status of the IAS query */ - - /* -------------------- Discovery log part -------------------- */ - /* Used by initial discovery on the control channel - * and by irnet_discover_daddr_and_lsap_sel() */ - struct irda_device_info *discoveries; /* Copy of the discovery log */ - int disco_index; /* Last read in the discovery log */ - int disco_number; /* Size of the discovery log */ +typedef struct irnet_socket { + /* ------------------- Instance management ------------------- */ + /* We manage a linked list of IrNET socket instances */ + irda_queue_t q; /* Must be first - for hasbin */ + int magic; /* Paranoia */ + + /* --------------------- FileSystem part --------------------- */ + /* "pppd" interact directly with us on a /dev/ file */ + struct file *file; /* File descriptor of this instance */ + /* TTY stuff - to keep "pppd" happy */ + struct termios termios; /* Various tty flags */ + /* Stuff for the control channel */ + int event_index; /* Last read in the event log */ + + /* ------------------------- PPP part ------------------------- */ + /* We interface directly to the ppp_generic driver in the kernel */ + int ppp_open; /* registered with ppp_generic */ + struct ppp_channel chan; /* Interface to generic ppp layer */ + + int mru; /* Max size of PPP payload */ + u32 xaccm[8]; /* Asynchronous character map (just */ + u32 raccm; /* to please pppd - dummy) */ + unsigned int flags; /* PPP flags (compression, ...) */ + unsigned int rbits; /* Unused receive flags ??? */ + + /* ------------------------ IrTTP part ------------------------ */ + /* We create a pseudo "socket" over the IrDA tranport */ + unsigned long ttp_open; /* Set when IrTTP is ready */ + unsigned long ttp_connect; /* Set when IrTTP is connecting */ + struct tsap_cb *tsap; /* IrTTP instance (the connection) */ + + char rname[NICKNAME_MAX_LEN + 1]; + /* IrDA nickname of destination */ + __u32 rdaddr; /* Requested peer IrDA address */ + __u32 rsaddr; /* Requested local IrDA address */ + __u32 daddr; /* actual peer IrDA address */ + __u32 saddr; /* my local IrDA address */ + __u8 dtsap_sel; /* Remote TSAP selector */ + __u8 stsap_sel; /* Local TSAP selector */ + + __u32 max_sdu_size_rx; /* Socket parameters used for IrTTP */ + __u32 max_sdu_size_tx; + __u32 max_data_size; + __u8 max_header_size; + LOCAL_FLOW tx_flow; /* State of the Tx path in IrTTP */ + + /* ------------------- IrLMP and IrIAS part ------------------- */ + /* Used for IrDA Discovery and socket name resolution */ + void *ckey; /* IrLMP client handle */ + __u16 mask; /* Hint bits mask (filter discov.) */ + int nslots; /* Number of slots for discovery */ + + struct iriap_cb *iriap; /* Used to query remote IAS */ + int errno; /* status of the IAS query */ + + /* -------------------- Discovery log part -------------------- */ + /* Used by initial discovery on the control channel + * and by irnet_discover_daddr_and_lsap_sel() */ + struct irda_device_info *discoveries; /* Copy of the discovery log */ + int disco_index; /* Last read in the discovery log */ + int disco_number; /* Size of the discovery log */ } irnet_socket; /* * This is the various event that we will generate on the control channel */ -typedef enum irnet_event -{ - IRNET_DISCOVER, /* New IrNET node discovered */ - IRNET_EXPIRE, /* IrNET node expired */ - IRNET_CONNECT_TO, /* IrNET socket has connected to other node */ - IRNET_CONNECT_FROM, /* Other node has connected to IrNET socket */ - IRNET_REQUEST_FROM, /* Non satisfied connection request */ - IRNET_NOANSWER_FROM, /* Failed connection request */ - IRNET_BLOCKED_LINK, /* Link (IrLAP) is blocked for > 3s */ - IRNET_DISCONNECT_FROM, /* IrNET socket has disconnected */ - IRNET_DISCONNECT_TO /* Closing IrNET socket */ +typedef enum irnet_event { + IRNET_DISCOVER, /* New IrNET node discovered */ + IRNET_EXPIRE, /* IrNET node expired */ + IRNET_CONNECT_TO, /* IrNET socket has connected to other node */ + IRNET_CONNECT_FROM, /* Other node has connected to IrNET socket */ + IRNET_REQUEST_FROM, /* Non satisfied connection request */ + IRNET_NOANSWER_FROM, /* Failed connection request */ + IRNET_BLOCKED_LINK, /* Link (IrLAP) is blocked for > 3s */ + IRNET_DISCONNECT_FROM, /* IrNET socket has disconnected */ + IRNET_DISCONNECT_TO /* Closing IrNET socket */ } irnet_event; /* * This is the storage for an event and its arguments */ -typedef struct irnet_log -{ - irnet_event event; - int unit; - __u32 saddr; - __u32 daddr; - char name[NICKNAME_MAX_LEN + 1]; /* 21 + 1 */ - __u16_host_order hints; /* Discovery hint bits */ +typedef struct irnet_log { + irnet_event event; + int unit; + __u32 saddr; + __u32 daddr; + char name[NICKNAME_MAX_LEN + 1]; /* 21 + 1 */ + __u16_host_order hints; /* Discovery hint bits */ } irnet_log; /* * This is the storage for all events and related stuff... */ -typedef struct irnet_ctrl_channel -{ - irnet_log log[IRNET_MAX_EVENTS]; /* Event log */ - int index; /* Current index in log */ - spinlock_t spinlock; /* Serialize access to the event log */ - wait_queue_head_t rwait; /* processes blocked on read (or poll) */ +typedef struct irnet_ctrl_channel { + irnet_log log[IRNET_MAX_EVENTS]; /* Event log */ + int index; /* Current index in log */ + spinlock_t spinlock; /* Serialize access to the event log */ + wait_queue_head_t rwait; /* processes blocked on read (or poll) */ } irnet_ctrl_channel; /**************************** PROTOTYPES ****************************/ @@ -506,20 +502,15 @@ typedef struct irnet_ctrl_channel */ /* -------------------------- IRDA PART -------------------------- */ -extern int - irda_irnet_create(irnet_socket *); /* Initialise a IrNET socket */ -extern int - irda_irnet_connect(irnet_socket *); /* Try to connect over IrDA */ -extern void - irda_irnet_destroy(irnet_socket *); /* Teardown a IrNET socket */ -extern int - irda_irnet_init(void); /* Initialise IrDA part of IrNET */ -extern void - irda_irnet_cleanup(void); /* Teardown IrDA part of IrNET */ +extern int irda_irnet_create(irnet_socket *); /* Initialise a IrNET socket */ +extern int irda_irnet_connect(irnet_socket *); /* Try to connect over IrDA */ +extern void irda_irnet_destroy(irnet_socket *); /* Teardown a IrNET socket */ +extern int irda_irnet_init(void); /* Initialise IrDA part of IrNET */ +extern void irda_irnet_cleanup(void); /* Teardown IrDA part of IrNET */ /**************************** VARIABLES ****************************/ /* Control channel stuff - allocated in irnet_irda.h */ -extern struct irnet_ctrl_channel irnet_events; +extern struct irnet_ctrl_channel irnet_events; -#endif /* IRNET_H */ +#endif /* IRNET_H */ diff --git a/net/irda/irnet/irnet_irda.h b/net/irda/irnet/irnet_irda.h index 0ba92d0..16b2af3 100644 --- a/net/irda/irnet/irnet_irda.h +++ b/net/irda/irnet/irnet_irda.h @@ -38,149 +38,91 @@ * the IrNET server (listen for connection requests) and the root * of the IrNET socket list */ -typedef struct irnet_root -{ - irnet_socket s; /* To pretend we are a client... */ +typedef struct irnet_root { + irnet_socket s; /* To pretend we are a client... */ - /* Generic stuff */ - int magic; /* Paranoia */ - int running; /* Are we operational ? */ + /* Generic stuff */ + int magic; /* Paranoia */ + int running; /* Are we operational ? */ - /* Link list of all IrNET instances opened */ - hashbin_t * list; - spinlock_t spinlock; /* Serialize access to the list */ - /* Note : the way hashbin has been designed is absolutely not - * reentrant, beware... So, we blindly protect all with spinlock */ + /* Link list of all IrNET instances opened */ + hashbin_t *list; + spinlock_t spinlock; /* Serialize access to the list */ + /* Note : the way hashbin has been designed is absolutely not + * reentrant, beware... So, we blindly protect all with spinlock */ - /* Handle for the hint bit advertised in IrLMP */ - void * skey; + /* Handle for the hint bit advertised in IrLMP */ + void *skey; - /* Server socket part */ - struct ias_object * ias_obj; /* Our service name + lsap in IAS */ + /* Server socket part */ + struct ias_object *ias_obj; /* Our service name + lsap in IAS */ } irnet_root; - /**************************** PROTOTYPES ****************************/ /* ----------------------- CONTROL CHANNEL ----------------------- */ static void - irnet_post_event(irnet_socket *, - irnet_event, - __u32, - __u32, - char *, - __u16); +irnet_post_event(irnet_socket *, irnet_event, __u32, __u32, char *, __u16); /* ----------------------- IRDA SUBROUTINES ----------------------- */ -static inline int - irnet_open_tsap(irnet_socket *); -static inline __u8 - irnet_ias_to_tsap(irnet_socket *, - int, - struct ias_value *); -static inline int - irnet_find_lsap_sel(irnet_socket *); -static inline int - irnet_connect_tsap(irnet_socket *); -static inline int - irnet_discover_next_daddr(irnet_socket *); -static inline int - irnet_discover_daddr_and_lsap_sel(irnet_socket *); -static inline int - irnet_dname_to_daddr(irnet_socket *); +static inline int irnet_open_tsap(irnet_socket *); +static inline __u8 irnet_ias_to_tsap(irnet_socket *, int, struct ias_value *); +static inline int irnet_find_lsap_sel(irnet_socket *); +static inline int irnet_connect_tsap(irnet_socket *); +static inline int irnet_discover_next_daddr(irnet_socket *); +static inline int irnet_discover_daddr_and_lsap_sel(irnet_socket *); +static inline int irnet_dname_to_daddr(irnet_socket *); /* ------------------------ SERVER SOCKET ------------------------ */ +static inline int irnet_daddr_to_dname(irnet_socket *); +static inline irnet_socket *irnet_find_socket(irnet_socket *); static inline int - irnet_daddr_to_dname(irnet_socket *); -static inline irnet_socket * - irnet_find_socket(irnet_socket *); -static inline int - irnet_connect_socket(irnet_socket *, - irnet_socket *, - struct qos_info *, - __u32, - __u8); -static inline void - irnet_disconnect_server(irnet_socket *, - struct sk_buff *); -static inline int - irnet_setup_server(void); -static inline void - irnet_destroy_server(void); +irnet_connect_socket(irnet_socket *, + irnet_socket *, struct qos_info *, __u32, __u8); +static inline void irnet_disconnect_server(irnet_socket *, struct sk_buff *); +static inline int irnet_setup_server(void); +static inline void irnet_destroy_server(void); /* ---------------------- IRDA-TTP CALLBACKS ---------------------- */ -static int - irnet_data_indication(void *, /* instance */ - void *, /* sap */ - struct sk_buff *); -static void - irnet_disconnect_indication(void *, - void *, - LM_REASON, - struct sk_buff *); -static void - irnet_connect_confirm(void *, - void *, - struct qos_info *, - __u32, - __u8, - struct sk_buff *); +static int irnet_data_indication(void *, /* instance */ + void *, /* sap */ + struct sk_buff *); static void - irnet_flow_indication(void *, - void *, - LOCAL_FLOW); +irnet_disconnect_indication(void *, void *, LM_REASON, struct sk_buff *); static void - irnet_status_indication(void *, - LINK_STATUS, - LOCK_STATUS); +irnet_connect_confirm(void *, + void *, + struct qos_info *, __u32, __u8, struct sk_buff *); +static void irnet_flow_indication(void *, void *, LOCAL_FLOW); +static void irnet_status_indication(void *, LINK_STATUS, LOCK_STATUS); static void - irnet_connect_indication(void *, - void *, - struct qos_info *, - __u32, - __u8, - struct sk_buff *); +irnet_connect_indication(void *, + void *, + struct qos_info *, __u32, __u8, struct sk_buff *); /* -------------------- IRDA-IAS/LMP CALLBACKS -------------------- */ -static void - irnet_getvalue_confirm(int, - __u16, - struct ias_value *, - void *); -static void - irnet_discovervalue_confirm(int, - __u16, - struct ias_value *, - void *); +static void irnet_getvalue_confirm(int, __u16, struct ias_value *, void *); +static void irnet_discovervalue_confirm(int, __u16, + struct ias_value *, void *); #ifdef DISCOVERY_EVENTS -static void - irnet_discovery_indication(discinfo_t *, - DISCOVERY_MODE, - void *); -static void - irnet_expiry_indication(discinfo_t *, - DISCOVERY_MODE, - void *); +static void irnet_discovery_indication(discinfo_t *, DISCOVERY_MODE, void *); +static void irnet_expiry_indication(discinfo_t *, DISCOVERY_MODE, void *); #endif /* -------------------------- PROC ENTRY -------------------------- */ #ifdef CONFIG_PROC_FS -static int - irnet_proc_read(char *, - char **, - off_t, - int); -#endif /* CONFIG_PROC_FS */ +static int irnet_proc_read(char *, char **, off_t, int); +#endif /* CONFIG_PROC_FS */ /**************************** VARIABLES ****************************/ /* * The IrNET server. Listen to connection requests and co... */ -static struct irnet_root irnet_server; +static struct irnet_root irnet_server; /* Control channel stuff (note : extern) */ -struct irnet_ctrl_channel irnet_events; +struct irnet_ctrl_channel irnet_events; /* The /proc/net/irda directory, defined elsewhere... */ #ifdef CONFIG_PROC_FS extern struct proc_dir_entry *proc_irda; -#endif /* CONFIG_PROC_FS */ +#endif /* CONFIG_PROC_FS */ -#endif /* IRNET_IRDA_H */ +#endif /* IRNET_IRDA_H */ diff --git a/net/irda/irnet/irnet_ppp.c b/net/irda/irnet/irnet_ppp.c index 2f9f8dc..9f4fa05 100644 --- a/net/irda/irnet/irnet_ppp.c +++ b/net/irda/irnet/irnet_ppp.c @@ -40,132 +40,137 @@ static struct ppp_channel_ops irnet_ppp_ops = { * Note : the code is crude, but effective... */ static inline ssize_t -irnet_ctrl_write(irnet_socket * ap, - const char __user *buf, - size_t count) +irnet_ctrl_write(irnet_socket * ap, const char __user * buf, size_t count) { - char command[IRNET_MAX_COMMAND]; - char * start; /* Current command being processed */ - char * next; /* Next command to process */ - int length; /* Length of current command */ - - DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count); - - /* Check for overflow... */ - DABORT(count >= IRNET_MAX_COMMAND, -ENOMEM, - CTRL_ERROR, "Too much data !!!\n"); - - /* Get the data in the driver */ - if(copy_from_user(command, buf, count)) - { - DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); - return -EFAULT; - } - - /* Safe terminate the string */ - command[count] = '\0'; - DEBUG(CTRL_INFO, "Command line received is ``%s'' (%Zd).\n", - command, count); - - /* Check every commands in the command line */ - next = command; - while(next != NULL) - { - /* Look at the next command */ - start = next; - - /* Scrap whitespaces before the command */ - while(isspace(*start)) - start++; - - /* ',' is our command separator */ - next = strchr(start, ','); - if(next) - { - *next = '\0'; /* Terminate command */ - length = next - start; /* Length */ - next++; /* Skip the '\0' */ - } - else - length = strlen(start); - - DEBUG(CTRL_INFO, "Found command ``%s'' (%d).\n", start, length); - - /* Check if we recognised one of the known command - * We can't use "switch" with strings, so hack with "continue" */ - - /* First command : name -> Requested IrDA nickname */ - if(!strncmp(start, "name", 4)) - { - /* Copy the name only if is included and not "any" */ - if((length > 5) && (strcmp(start + 5, "any"))) - { - /* Strip out trailing whitespaces */ - while(isspace(start[length - 1])) - length--; - - /* Copy the name for later reuse */ - memcpy(ap->rname, start + 5, length - 5); - ap->rname[length - 5] = '\0'; - } - else - ap->rname[0] = '\0'; - DEBUG(CTRL_INFO, "Got rname = ``%s''\n", ap->rname); - - /* Restart the loop */ - continue; - } + char command[IRNET_MAX_COMMAND]; + char *start; /* Current command being processed */ + char *next; /* Next command to process */ + int length; /* Length of current command */ - /* Second command : addr, daddr -> Requested IrDA destination address - * Also process : saddr -> Requested IrDA source address */ - if((!strncmp(start, "addr", 4)) || - (!strncmp(start, "daddr", 5)) || - (!strncmp(start, "saddr", 5))) - { - __u32 addr = DEV_ADDR_ANY; - - /* Copy the address only if is included and not "any" */ - if((length > 5) && (strcmp(start + 5, "any"))) - { - char * begp = start + 5; - char * endp; - - /* Scrap whitespaces before the command */ - while(isspace(*begp)) - begp++; - - /* Convert argument to a number (last arg is the base) */ - addr = simple_strtoul(begp, &endp, 16); - /* Has it worked ? (endp should be start + length) */ - DABORT(endp <= (start + 5), -EINVAL, - CTRL_ERROR, "Invalid address.\n"); - } - /* Which type of address ? */ - if(start[0] == 's') - { - /* Save it */ - ap->rsaddr = addr; - DEBUG(CTRL_INFO, "Got rsaddr = %08x\n", ap->rsaddr); - } - else - { - /* Save it */ - ap->rdaddr = addr; - DEBUG(CTRL_INFO, "Got rdaddr = %08x\n", ap->rdaddr); - } - - /* Restart the loop */ - continue; - } + DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count); - /* Other possible command : connect N (number of retries) */ + /* Check for overflow... */ + DABORT(count >= IRNET_MAX_COMMAND, -ENOMEM, + CTRL_ERROR, "Too much data !!!\n"); - /* No command matched -> Failed... */ - DABORT(1, -EINVAL, CTRL_ERROR, "Not a recognised IrNET command.\n"); - } + /* Get the data in the driver */ + if (copy_from_user(command, buf, count)) { + DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); + return -EFAULT; + } + + /* Safe terminate the string */ + command[count] = '\0'; + DEBUG(CTRL_INFO, "Command line received is ``%s'' (%Zd).\n", + command, count); + + /* Check every commands in the command line */ + next = command; + while (next != NULL) { + /* Look at the next command */ + start = next; + + /* Scrap whitespaces before the command */ + while (isspace(*start)) + start++; + + /* ',' is our command separator */ + next = strchr(start, ','); + if (next) { + *next = '\0'; /* Terminate command */ + length = next - start; /* Length */ + next++; /* Skip the '\0' */ + } else + length = strlen(start); + + DEBUG(CTRL_INFO, "Found command ``%s'' (%d).\n", + start, length); + + /* + * Check if we recognised one of the known command + * We can't use "switch" with strings, so hack + * with "continue" + */ + + /* First command : name -> Requested IrDA nickname */ + if (!strncmp(start, "name", 4)) { + /* Copy the name only if is included and not "any" */ + if ((length > 5) && (strcmp(start + 5, "any"))) { + /* Strip out trailing whitespaces */ + while (isspace(start[length - 1])) + length--; + + /* Copy the name for later reuse */ + memcpy(ap->rname, start + 5, length - 5); + ap->rname[length - 5] = '\0'; + } else + ap->rname[0] = '\0'; + DEBUG(CTRL_INFO, "Got rname = ``%s''\n", ap->rname); + + /* Restart the loop */ + continue; + } + + /* + * Second command : addr, daddr -> Requested IrDA + * destination address + * Also process : saddr -> Requested IrDA source address + */ + if ((!strncmp(start, "addr", 4)) || + (!strncmp(start, "daddr", 5)) || + (!strncmp(start, "saddr", 5))) { + __u32 addr = DEV_ADDR_ANY; + + /* + * Copy the address only if + * is included and not "any" + */ + if ((length > 5) && (strcmp(start + 5, "any"))) { + char *begp = start + 5; + char *endp; + + /* Scrap whitespaces before the command */ + while (isspace(*begp)) + begp++; + + /* + * Convert argument to a number + * (last arg is the base) + */ + addr = simple_strtoul(begp, &endp, 16); + /* + * Has it worked ? + * (endp should be start + length) + */ + DABORT(endp <= (start + 5), -EINVAL, + CTRL_ERROR, "Invalid address.\n"); + } + /* Which type of address ? */ + if (start[0] == 's') { + /* Save it */ + ap->rsaddr = addr; + DEBUG(CTRL_INFO, "Got rsaddr = %08x\n", + ap->rsaddr); + } else { + /* Save it */ + ap->rdaddr = addr; + DEBUG(CTRL_INFO, "Got rdaddr = %08x\n", + ap->rdaddr); + } + + /* Restart the loop */ + continue; + } + + /* Other possible command : connect N (number of retries) */ + + /* No command matched -> Failed... */ + DABORT(1, -EINVAL, CTRL_ERROR, + "Not a recognised IrNET command.\n"); + } - /* Success : we have parsed all commands successfully */ - return(count); + /* Success : we have parsed all commands successfully */ + return (count); } #ifdef INITIAL_DISCOVERY @@ -178,21 +183,20 @@ irnet_ctrl_write(irnet_socket * ap, * This function query the current content of the discovery log * at the startup of the event channel and save it in the internal struct. */ -static void -irnet_get_discovery_log(irnet_socket * ap) +static void irnet_get_discovery_log(irnet_socket * ap) { - __u16 mask = irlmp_service_to_hint(S_LAN); + __u16 mask = irlmp_service_to_hint(S_LAN); - /* Ask IrLMP for the current discovery log */ - ap->discoveries = irlmp_get_discoveries(&ap->disco_number, mask, - DISCOVERY_DEFAULT_SLOTS); + /* Ask IrLMP for the current discovery log */ + ap->discoveries = irlmp_get_discoveries(&ap->disco_number, mask, + DISCOVERY_DEFAULT_SLOTS); - /* Check if the we got some results */ - if(ap->discoveries == NULL) - ap->disco_number = -1; + /* Check if the we got some results */ + if (ap->discoveries == NULL) + ap->disco_number = -1; - DEBUG(CTRL_INFO, "Got the log (0x%p), size is %d\n", - ap->discoveries, ap->disco_number); + DEBUG(CTRL_INFO, "Got the log (0x%p), size is %d\n", + ap->discoveries, ap->disco_number); } /*------------------------------------------------------------------*/ @@ -210,205 +214,194 @@ irnet_get_discovery_log(irnet_socket * ap) * While reading : discoveries = ptr ; disco_index = X ; disco_number = Y * After reading : discoveries = NULL ; disco_index = Y ; disco_number = -1 */ -static inline int -irnet_read_discovery_log(irnet_socket * ap, - char * event) +static inline int irnet_read_discovery_log(irnet_socket * ap, char *event) { - int done_event = 0; - - DENTER(CTRL_TRACE, "(ap=0x%p, event=0x%p)\n", - ap, event); - - /* Test if we have some work to do or we have already finished */ - if(ap->disco_number == -1) - { - DEBUG(CTRL_INFO, "Already done\n"); - return 0; - } - - /* Test if it's the first time and therefore we need to get the log */ - if(ap->discoveries == NULL) - irnet_get_discovery_log(ap); - - /* Check if we have more item to dump */ - if(ap->disco_index < ap->disco_number) - { - /* Write an event */ - sprintf(event, "Found %08x (%s) behind %08x {hints %02X-%02X}\n", - ap->discoveries[ap->disco_index].daddr, - ap->discoveries[ap->disco_index].info, - ap->discoveries[ap->disco_index].saddr, - ap->discoveries[ap->disco_index].hints[0], - ap->discoveries[ap->disco_index].hints[1]); - DEBUG(CTRL_INFO, "Writing discovery %d : %s\n", - ap->disco_index, ap->discoveries[ap->disco_index].info); - - /* We have an event */ - done_event = 1; - /* Next discovery */ - ap->disco_index++; - } - - /* Check if we have done the last item */ - if(ap->disco_index >= ap->disco_number) - { - /* No more items : remove the log and signal termination */ - DEBUG(CTRL_INFO, "Cleaning up log (0x%p)\n", - ap->discoveries); - if(ap->discoveries != NULL) - { - /* Cleanup our copy of the discovery log */ - kfree(ap->discoveries); - ap->discoveries = NULL; + int done_event = 0; + + DENTER(CTRL_TRACE, "(ap=0x%p, event=0x%p)\n", ap, event); + + /* Test if we have some work to do or we have already finished */ + if (ap->disco_number == -1) { + DEBUG(CTRL_INFO, "Already done\n"); + return 0; } - ap->disco_number = -1; - } - return done_event; + /* Test if it's the first time and therefore we need to get the log */ + if (ap->discoveries == NULL) + irnet_get_discovery_log(ap); + + /* Check if we have more item to dump */ + if (ap->disco_index < ap->disco_number) { + /* Write an event */ + sprintf(event, + "Found %08x (%s) behind %08x {hints %02X-%02X}\n", + ap->discoveries[ap->disco_index].daddr, + ap->discoveries[ap->disco_index].info, + ap->discoveries[ap->disco_index].saddr, + ap->discoveries[ap->disco_index].hints[0], + ap->discoveries[ap->disco_index].hints[1]); + DEBUG(CTRL_INFO, "Writing discovery %d : %s\n", + ap->disco_index, + ap->discoveries[ap->disco_index].info); + + /* We have an event */ + done_event = 1; + /* Next discovery */ + ap->disco_index++; + } + + /* Check if we have done the last item */ + if (ap->disco_index >= ap->disco_number) { + /* No more items : remove the log and signal termination */ + DEBUG(CTRL_INFO, "Cleaning up log (0x%p)\n", ap->discoveries); + if (ap->discoveries != NULL) { + /* Cleanup our copy of the discovery log */ + kfree(ap->discoveries); + ap->discoveries = NULL; + } + ap->disco_number = -1; + } + + return done_event; } -#endif /* INITIAL_DISCOVERY */ +#endif /* INITIAL_DISCOVERY */ /*------------------------------------------------------------------*/ /* * Read is used to get IrNET events */ static inline ssize_t -irnet_ctrl_read(irnet_socket * ap, - struct file * file, - char __user * buf, - size_t count) +irnet_ctrl_read(irnet_socket * ap, + struct file *file, char __user * buf, size_t count) { - DECLARE_WAITQUEUE(wait, current); - char event[64]; /* Max event is 61 char */ - ssize_t ret = 0; + DECLARE_WAITQUEUE(wait, current); + char event[64]; /* Max event is 61 char */ + ssize_t ret = 0; - DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count); + DENTER(CTRL_TRACE, "(ap=0x%p, count=%Zd)\n", ap, count); - /* Check if we can write an event out in one go */ - DABORT(count < sizeof(event), -EOVERFLOW, CTRL_ERROR, "Buffer to small.\n"); + /* Check if we can write an event out in one go */ + DABORT(count < sizeof(event), -EOVERFLOW, CTRL_ERROR, + "Buffer to small.\n"); #ifdef INITIAL_DISCOVERY - /* Check if we have read the log */ - if(irnet_read_discovery_log(ap, event)) - { - /* We have an event !!! Copy it to the user */ - if(copy_to_user(buf, event, strlen(event))) - { - DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); - return -EFAULT; + /* Check if we have read the log */ + if (irnet_read_discovery_log(ap, event)) { + /* We have an event !!! Copy it to the user */ + if (copy_to_user(buf, event, strlen(event))) { + DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); + return -EFAULT; + } + + DEXIT(CTRL_TRACE, "\n"); + return (strlen(event)); + } +#endif /* INITIAL_DISCOVERY */ + + /* Put ourselves on the wait queue to be woken up */ + add_wait_queue(&irnet_events.rwait, &wait); + current->state = TASK_INTERRUPTIBLE; + for (;;) { + /* If there is unread events */ + ret = 0; + if (ap->event_index != irnet_events.index) + break; + ret = -EAGAIN; + if (file->f_flags & O_NONBLOCK) + break; + ret = -ERESTARTSYS; + if (signal_pending(current)) + break; + /* Yield and wait to be woken up */ + schedule(); + } + current->state = TASK_RUNNING; + remove_wait_queue(&irnet_events.rwait, &wait); + + /* Did we got it ? */ + if (ret != 0) { + /* No, return the error code */ + DEXIT(CTRL_TRACE, " - ret %Zd\n", ret); + return ret; + } + + /* Which event is it ? */ + switch (irnet_events.log[ap->event_index].event) { + case IRNET_DISCOVER: + sprintf(event, + "Discovered %08x (%s) behind %08x {hints %02X-%02X}\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].saddr, + irnet_events.log[ap->event_index].hints.byte[0], + irnet_events.log[ap->event_index].hints.byte[1]); + break; + case IRNET_EXPIRE: + sprintf(event, + "Expired %08x (%s) behind %08x {hints %02X-%02X}\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].saddr, + irnet_events.log[ap->event_index].hints.byte[0], + irnet_events.log[ap->event_index].hints.byte[1]); + break; + case IRNET_CONNECT_TO: + sprintf(event, "Connected to %08x (%s) on ppp%d\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].unit); + break; + case IRNET_CONNECT_FROM: + sprintf(event, "Connection from %08x (%s) on ppp%d\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].unit); + break; + case IRNET_REQUEST_FROM: + sprintf(event, "Request from %08x (%s) behind %08x\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].saddr); + break; + case IRNET_NOANSWER_FROM: + sprintf(event, "No-answer from %08x (%s) on ppp%d\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].unit); + break; + case IRNET_BLOCKED_LINK: + sprintf(event, "Blocked link with %08x (%s) on ppp%d\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].unit); + break; + case IRNET_DISCONNECT_FROM: + sprintf(event, "Disconnection from %08x (%s) on ppp%d\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name, + irnet_events.log[ap->event_index].unit); + break; + case IRNET_DISCONNECT_TO: + sprintf(event, "Disconnected to %08x (%s)\n", + irnet_events.log[ap->event_index].daddr, + irnet_events.log[ap->event_index].name); + break; + default: + sprintf(event, "Bug\n"); } + /* Increment our event index */ + ap->event_index = (ap->event_index + 1) % IRNET_MAX_EVENTS; - DEXIT(CTRL_TRACE, "\n"); - return(strlen(event)); - } -#endif /* INITIAL_DISCOVERY */ - - /* Put ourselves on the wait queue to be woken up */ - add_wait_queue(&irnet_events.rwait, &wait); - current->state = TASK_INTERRUPTIBLE; - for(;;) - { - /* If there is unread events */ - ret = 0; - if(ap->event_index != irnet_events.index) - break; - ret = -EAGAIN; - if(file->f_flags & O_NONBLOCK) - break; - ret = -ERESTARTSYS; - if(signal_pending(current)) - break; - /* Yield and wait to be woken up */ - schedule(); - } - current->state = TASK_RUNNING; - remove_wait_queue(&irnet_events.rwait, &wait); - - /* Did we got it ? */ - if(ret != 0) - { - /* No, return the error code */ - DEXIT(CTRL_TRACE, " - ret %Zd\n", ret); - return ret; - } - - /* Which event is it ? */ - switch(irnet_events.log[ap->event_index].event) - { - case IRNET_DISCOVER: - sprintf(event, "Discovered %08x (%s) behind %08x {hints %02X-%02X}\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].saddr, - irnet_events.log[ap->event_index].hints.byte[0], - irnet_events.log[ap->event_index].hints.byte[1]); - break; - case IRNET_EXPIRE: - sprintf(event, "Expired %08x (%s) behind %08x {hints %02X-%02X}\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].saddr, - irnet_events.log[ap->event_index].hints.byte[0], - irnet_events.log[ap->event_index].hints.byte[1]); - break; - case IRNET_CONNECT_TO: - sprintf(event, "Connected to %08x (%s) on ppp%d\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].unit); - break; - case IRNET_CONNECT_FROM: - sprintf(event, "Connection from %08x (%s) on ppp%d\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].unit); - break; - case IRNET_REQUEST_FROM: - sprintf(event, "Request from %08x (%s) behind %08x\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].saddr); - break; - case IRNET_NOANSWER_FROM: - sprintf(event, "No-answer from %08x (%s) on ppp%d\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].unit); - break; - case IRNET_BLOCKED_LINK: - sprintf(event, "Blocked link with %08x (%s) on ppp%d\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].unit); - break; - case IRNET_DISCONNECT_FROM: - sprintf(event, "Disconnection from %08x (%s) on ppp%d\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name, - irnet_events.log[ap->event_index].unit); - break; - case IRNET_DISCONNECT_TO: - sprintf(event, "Disconnected to %08x (%s)\n", - irnet_events.log[ap->event_index].daddr, - irnet_events.log[ap->event_index].name); - break; - default: - sprintf(event, "Bug\n"); - } - /* Increment our event index */ - ap->event_index = (ap->event_index + 1) % IRNET_MAX_EVENTS; - - DEBUG(CTRL_INFO, "Event is :%s", event); - - /* Copy it to the user */ - if(copy_to_user(buf, event, strlen(event))) - { - DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); - return -EFAULT; - } - - DEXIT(CTRL_TRACE, "\n"); - return(strlen(event)); + DEBUG(CTRL_INFO, "Event is :%s", event); + + /* Copy it to the user */ + if (copy_to_user(buf, event, strlen(event))) { + DERROR(CTRL_ERROR, "Invalid user space pointer.\n"); + return -EFAULT; + } + + DEXIT(CTRL_TRACE, "\n"); + return (strlen(event)); } /*------------------------------------------------------------------*/ @@ -417,35 +410,34 @@ irnet_ctrl_read(irnet_socket * ap, * Just check if there are new events... */ static inline unsigned int -irnet_ctrl_poll(irnet_socket * ap, - struct file * file, - poll_table * wait) +irnet_ctrl_poll(irnet_socket * ap, struct file *file, poll_table * wait) { - unsigned int mask; + unsigned int mask; - DENTER(CTRL_TRACE, "(ap=0x%p)\n", ap); + DENTER(CTRL_TRACE, "(ap=0x%p)\n", ap); - poll_wait(file, &irnet_events.rwait, wait); - mask = POLLOUT | POLLWRNORM; - /* If there is unread events */ - if(ap->event_index != irnet_events.index) - mask |= POLLIN | POLLRDNORM; + poll_wait(file, &irnet_events.rwait, wait); + mask = POLLOUT | POLLWRNORM; + /* If there is unread events */ + if (ap->event_index != irnet_events.index) + mask |= POLLIN | POLLRDNORM; #ifdef INITIAL_DISCOVERY - if(ap->disco_number != -1) - { - /* Test if it's the first time and therefore we need to get the log */ - if(ap->discoveries == NULL) - irnet_get_discovery_log(ap); - /* Recheck */ - if(ap->disco_number != -1) - mask |= POLLIN | POLLRDNORM; - } -#endif /* INITIAL_DISCOVERY */ - - DEXIT(CTRL_TRACE, " - mask=0x%X\n", mask); - return mask; -} + if (ap->disco_number != -1) { + /* + * Test if it's the first time and therefore + * we need to get the log + */ + if (ap->discoveries == NULL) + irnet_get_discovery_log(ap); + /* Recheck */ + if (ap->disco_number != -1) + mask |= POLLIN | POLLRDNORM; + } +#endif /* INITIAL_DISCOVERY */ + DEXIT(CTRL_TRACE, " - mask=0x%X\n", mask); + return mask; +} /*********************** FILESYSTEM CALLBACKS ***********************/ /* @@ -460,93 +452,90 @@ irnet_ctrl_poll(irnet_socket * ap, * Open : when somebody open /dev/irnet * We basically create a new instance of irnet and initialise it. */ -static int -dev_irnet_open(struct inode * inode, - struct file * file) +static int dev_irnet_open(struct inode *inode, struct file *file) { - struct irnet_socket * ap; - int err; + struct irnet_socket *ap; + int err; - DENTER(FS_TRACE, "(file=0x%p)\n", file); + DENTER(FS_TRACE, "(file=0x%p)\n", file); #ifdef SECURE_DEVIRNET - /* This could (should?) be enforced by the permissions on /dev/irnet. */ - if(!capable(CAP_NET_ADMIN)) - return -EPERM; -#endif /* SECURE_DEVIRNET */ - - /* Allocate a private structure for this IrNET instance */ - ap = kzalloc(sizeof(*ap), GFP_KERNEL); - DABORT(ap == NULL, -ENOMEM, FS_ERROR, "Can't allocate struct irnet...\n"); - - /* initialize the irnet structure */ - ap->file = file; - - /* PPP channel setup */ - ap->ppp_open = 0; - ap->chan.private = ap; - ap->chan.ops = &irnet_ppp_ops; - ap->chan.mtu = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN); - ap->chan.hdrlen = 2 + TTP_MAX_HEADER; /* for A/C + Max IrDA hdr */ - /* PPP parameters */ - ap->mru = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN); - ap->xaccm[0] = ~0U; - ap->xaccm[3] = 0x60000000U; - ap->raccm = ~0U; - - /* Setup the IrDA part... */ - err = irda_irnet_create(ap); - if(err) - { - DERROR(FS_ERROR, "Can't setup IrDA link...\n"); - kfree(ap); - return err; - } - - /* For the control channel */ - ap->event_index = irnet_events.index; /* Cancel all past events */ - - /* Put our stuff where we will be able to find it later */ - file->private_data = ap; - - DEXIT(FS_TRACE, " - ap=0x%p\n", ap); - return 0; -} + /* + * This could (should?) be enforced by + * the permissions on /dev/irnet. + */ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; +#endif /* SECURE_DEVIRNET */ + + /* Allocate a private structure for this IrNET instance */ + ap = kzalloc(sizeof(*ap), GFP_KERNEL); + DABORT(ap == NULL, -ENOMEM, FS_ERROR, + "Can't allocate struct irnet...\n"); + + /* initialize the irnet structure */ + ap->file = file; + + /* PPP channel setup */ + ap->ppp_open = 0; + ap->chan.private = ap; + ap->chan.ops = &irnet_ppp_ops; + ap->chan.mtu = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN); + ap->chan.hdrlen = 2 + TTP_MAX_HEADER; /* for A/C + Max IrDA hdr */ + /* PPP parameters */ + ap->mru = (2048 - TTP_MAX_HEADER - 2 - PPP_HDRLEN); + ap->xaccm[0] = ~0U; + ap->xaccm[3] = 0x60000000U; + ap->raccm = ~0U; + + /* Setup the IrDA part... */ + err = irda_irnet_create(ap); + if (err) { + DERROR(FS_ERROR, "Can't setup IrDA link...\n"); + kfree(ap); + return err; + } + + /* For the control channel */ + ap->event_index = irnet_events.index; /* Cancel all past events */ + /* Put our stuff where we will be able to find it later */ + file->private_data = ap; + + DEXIT(FS_TRACE, " - ap=0x%p\n", ap); + return 0; +} /*------------------------------------------------------------------*/ /* * Close : when somebody close /dev/irnet * Destroy the instance of /dev/irnet */ -static int -dev_irnet_close(struct inode * inode, - struct file * file) +static int dev_irnet_close(struct inode *inode, struct file *file) { - irnet_socket * ap = (struct irnet_socket *) file->private_data; + irnet_socket *ap = (struct irnet_socket *)file->private_data; - DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n", - file, ap); - DABORT(ap == NULL, 0, FS_ERROR, "ap is NULL !!!\n"); + DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n", file, ap); + DABORT(ap == NULL, 0, FS_ERROR, "ap is NULL !!!\n"); - /* Detach ourselves */ - file->private_data = NULL; + /* Detach ourselves */ + file->private_data = NULL; - /* Close IrDA stuff */ - irda_irnet_destroy(ap); + /* Close IrDA stuff */ + irda_irnet_destroy(ap); - /* Disconnect from the generic PPP layer if not already done */ - if(ap->ppp_open) - { - DERROR(FS_ERROR, "Channel still registered - deregistering !\n"); - ap->ppp_open = 0; - ppp_unregister_channel(&ap->chan); - } + /* Disconnect from the generic PPP layer if not already done */ + if (ap->ppp_open) { + DERROR(FS_ERROR, + "Channel still registered - deregistering !\n"); + ap->ppp_open = 0; + ppp_unregister_channel(&ap->chan); + } - kfree(ap); + kfree(ap); - DEXIT(FS_TRACE, "\n"); - return 0; + DEXIT(FS_TRACE, "\n"); + return 0; } /*------------------------------------------------------------------*/ @@ -555,22 +544,19 @@ dev_irnet_close(struct inode * inode, * (we receive packet from ppp_generic through ppp_irnet_send()) */ static ssize_t -dev_irnet_write(struct file * file, - const char __user *buf, - size_t count, - loff_t * ppos) +dev_irnet_write(struct file *file, + const char __user * buf, size_t count, loff_t * ppos) { - irnet_socket * ap = (struct irnet_socket *) file->private_data; + irnet_socket *ap = (struct irnet_socket *)file->private_data; - DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n", - file, ap, count); - DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n"); + DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n", file, ap, count); + DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n"); - /* If we are connected to ppp_generic, let it handle the job */ - if(ap->ppp_open) - return -EAGAIN; - else - return irnet_ctrl_write(ap, buf, count); + /* If we are connected to ppp_generic, let it handle the job */ + if (ap->ppp_open) + return -EAGAIN; + else + return irnet_ctrl_write(ap, buf, count); } /*------------------------------------------------------------------*/ @@ -579,47 +565,41 @@ dev_irnet_write(struct file * file, * (pppd poll us, but ultimately reads through /dev/ppp) */ static ssize_t -dev_irnet_read(struct file * file, - char __user * buf, - size_t count, - loff_t * ppos) +dev_irnet_read(struct file *file, + char __user * buf, size_t count, loff_t * ppos) { - irnet_socket * ap = (struct irnet_socket *) file->private_data; + irnet_socket *ap = (struct irnet_socket *)file->private_data; - DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n", - file, ap, count); - DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n"); + DPASS(FS_TRACE, "(file=0x%p, ap=0x%p, count=%Zd)\n", file, ap, count); + DABORT(ap == NULL, -ENXIO, FS_ERROR, "ap is NULL !!!\n"); - /* If we are connected to ppp_generic, let it handle the job */ - if(ap->ppp_open) - return -EAGAIN; - else - return irnet_ctrl_read(ap, file, buf, count); + /* If we are connected to ppp_generic, let it handle the job */ + if (ap->ppp_open) + return -EAGAIN; + else + return irnet_ctrl_read(ap, file, buf, count); } /*------------------------------------------------------------------*/ /* * Poll : called when someone do a select on /dev/irnet */ -static unsigned int -dev_irnet_poll(struct file * file, - poll_table * wait) +static unsigned int dev_irnet_poll(struct file *file, poll_table * wait) { - irnet_socket * ap = (struct irnet_socket *) file->private_data; - unsigned int mask; + irnet_socket *ap = (struct irnet_socket *)file->private_data; + unsigned int mask; - DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n", - file, ap); + DENTER(FS_TRACE, "(file=0x%p, ap=0x%p)\n", file, ap); - mask = POLLOUT | POLLWRNORM; - DABORT(ap == NULL, mask, FS_ERROR, "ap is NULL !!!\n"); + mask = POLLOUT | POLLWRNORM; + DABORT(ap == NULL, mask, FS_ERROR, "ap is NULL !!!\n"); - /* If we are connected to ppp_generic, let it handle the job */ - if(!ap->ppp_open) - mask |= irnet_ctrl_poll(ap, file, wait); + /* If we are connected to ppp_generic, let it handle the job */ + if (!ap->ppp_open) + mask |= irnet_ctrl_poll(ap, file, wait); - DEXIT(FS_TRACE, " - mask=0x%X\n", mask); - return(mask); + DEXIT(FS_TRACE, " - mask=0x%X\n", mask); + return (mask); } /*------------------------------------------------------------------*/ @@ -629,160 +609,158 @@ dev_irnet_poll(struct file * file, * instance is active. */ static int -dev_irnet_ioctl(struct inode * inode, - struct file * file, - unsigned int cmd, - unsigned long arg) +dev_irnet_ioctl(struct inode *inode, + struct file *file, unsigned int cmd, unsigned long arg) { - irnet_socket * ap = (struct irnet_socket *) file->private_data; - int err; - int val; - void __user *argp = (void __user *)arg; + irnet_socket *ap = (struct irnet_socket *)file->private_data; + int err; + int val; + void __user *argp = (void __user *)arg; - DENTER(FS_TRACE, "(file=0x%p, ap=0x%p, cmd=0x%X)\n", - file, ap, cmd); + DENTER(FS_TRACE, "(file=0x%p, ap=0x%p, cmd=0x%X)\n", file, ap, cmd); - /* Basic checks... */ - DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n"); + /* Basic checks... */ + DASSERT(ap != NULL, -ENXIO, PPP_ERROR, "ap is NULL...\n"); #ifdef SECURE_DEVIRNET - if(!capable(CAP_NET_ADMIN)) - return -EPERM; -#endif /* SECURE_DEVIRNET */ - - err = -EFAULT; - switch(cmd) - { - /* Set discipline (should be N_SYNC_PPP or N_TTY) */ - case TIOCSETD: - if(get_user(val, (int __user *)argp)) - break; - if((val == N_SYNC_PPP) || (val == N_PPP)) - { - DEBUG(FS_INFO, "Entering PPP discipline.\n"); - /* PPP channel setup (ap->chan in configued in dev_irnet_open())*/ - err = ppp_register_channel(&ap->chan); - if(err == 0) - { - /* Our ppp side is active */ - ap->ppp_open = 1; - - DEBUG(FS_INFO, "Trying to establish a connection.\n"); - /* Setup the IrDA link now - may fail... */ - irda_irnet_connect(ap); - } - else - DERROR(FS_ERROR, "Can't setup PPP channel...\n"); - } - else - { - /* In theory, should be N_TTY */ - DEBUG(FS_INFO, "Exiting PPP discipline.\n"); - /* Disconnect from the generic PPP layer */ - if(ap->ppp_open) - { - ap->ppp_open = 0; - ppp_unregister_channel(&ap->chan); - } - else - DERROR(FS_ERROR, "Channel not registered !\n"); - err = 0; - } - break; - - /* Query PPP channel and unit number */ - case PPPIOCGCHAN: - if(!ap->ppp_open) - break; - if(put_user(ppp_channel_index(&ap->chan), (int __user *)argp)) - break; - DEBUG(FS_INFO, "Query channel.\n"); - err = 0; - break; - case PPPIOCGUNIT: - if(!ap->ppp_open) - break; - if(put_user(ppp_unit_number(&ap->chan), (int __user *)argp)) - break; - DEBUG(FS_INFO, "Query unit number.\n"); - err = 0; - break; - - /* All these ioctls can be passed both directly and from ppp_generic, - * so we just deal with them in one place... - */ - case PPPIOCGFLAGS: - case PPPIOCSFLAGS: - case PPPIOCGASYNCMAP: - case PPPIOCSASYNCMAP: - case PPPIOCGRASYNCMAP: - case PPPIOCSRASYNCMAP: - case PPPIOCGXASYNCMAP: - case PPPIOCSXASYNCMAP: - case PPPIOCGMRU: - case PPPIOCSMRU: - DEBUG(FS_INFO, "Standard PPP ioctl.\n"); - if(!capable(CAP_NET_ADMIN)) - err = -EPERM; - else - err = ppp_irnet_ioctl(&ap->chan, cmd, arg); - break; - - /* TTY IOCTLs : Pretend that we are a tty, to keep pppd happy */ - /* Get termios */ - case TCGETS: - DEBUG(FS_INFO, "Get termios.\n"); - if(kernel_termios_to_user_termios((struct termios __user *)argp, &ap->termios)) - break; - err = 0; - break; - /* Set termios */ - case TCSETSF: - DEBUG(FS_INFO, "Set termios.\n"); - if(user_termios_to_kernel_termios(&ap->termios, (struct termios __user *)argp)) - break; - err = 0; - break; - - /* Set DTR/RTS */ - case TIOCMBIS: - case TIOCMBIC: - /* Set exclusive/non-exclusive mode */ - case TIOCEXCL: - case TIOCNXCL: - DEBUG(FS_INFO, "TTY compatibility.\n"); - err = 0; - break; - - case TCGETA: - DEBUG(FS_INFO, "TCGETA\n"); - break; - - case TCFLSH: - DEBUG(FS_INFO, "TCFLSH\n"); - /* Note : this will flush buffers in PPP, so it *must* be done - * We should also worry that we don't accept junk here and that - * we get rid of our own buffers */ + if (!capable(CAP_NET_ADMIN)) + return -EPERM; +#endif /* SECURE_DEVIRNET */ + + err = -EFAULT; + switch (cmd) { + /* Set discipline (should be N_SYNC_PPP or N_TTY) */ + case TIOCSETD: + if (get_user(val, (int __user *)argp)) + break; + if ((val == N_SYNC_PPP) || (val == N_PPP)) { + DEBUG(FS_INFO, "Entering PPP discipline.\n"); + /* + * PPP channel setup (ap->chan in configued + * in dev_irnet_open()) + */ + err = ppp_register_channel(&ap->chan); + if (err == 0) { + /* Our ppp side is active */ + ap->ppp_open = 1; + + DEBUG(FS_INFO, + "Trying to establish a connection.\n"); + /* Setup the IrDA link now - may fail... */ + irda_irnet_connect(ap); + } else + DERROR(FS_ERROR, + "Can't setup PPP channel...\n"); + } else { + /* In theory, should be N_TTY */ + DEBUG(FS_INFO, "Exiting PPP discipline.\n"); + /* Disconnect from the generic PPP layer */ + if (ap->ppp_open) { + ap->ppp_open = 0; + ppp_unregister_channel(&ap->chan); + } else + DERROR(FS_ERROR, "Channel not registered !\n"); + err = 0; + } + break; + + /* Query PPP channel and unit number */ + case PPPIOCGCHAN: + if (!ap->ppp_open) + break; + if (put_user(ppp_channel_index(&ap->chan), (int __user *)argp)) + break; + DEBUG(FS_INFO, "Query channel.\n"); + err = 0; + break; + case PPPIOCGUNIT: + if (!ap->ppp_open) + break; + if (put_user(ppp_unit_number(&ap->chan), (int __user *)argp)) + break; + DEBUG(FS_INFO, "Query unit number.\n"); + err = 0; + break; + + /* + * All these ioctls can be passed both directly + * and from ppp_generic, so we just deal with them + * in one place... + */ + case PPPIOCGFLAGS: + case PPPIOCSFLAGS: + case PPPIOCGASYNCMAP: + case PPPIOCSASYNCMAP: + case PPPIOCGRASYNCMAP: + case PPPIOCSRASYNCMAP: + case PPPIOCGXASYNCMAP: + case PPPIOCSXASYNCMAP: + case PPPIOCGMRU: + case PPPIOCSMRU: + DEBUG(FS_INFO, "Standard PPP ioctl.\n"); + if (!capable(CAP_NET_ADMIN)) + err = -EPERM; + else + err = ppp_irnet_ioctl(&ap->chan, cmd, arg); + break; + + /* TTY IOCTLs: Pretend that we are a tty, to keep pppd happy */ + /* Get termios */ + case TCGETS: + DEBUG(FS_INFO, "Get termios.\n"); + if (kernel_termios_to_user_termios + ((struct termios __user *)argp, &ap->termios)) + break; + err = 0; + break; + /* Set termios */ + case TCSETSF: + DEBUG(FS_INFO, "Set termios.\n"); + if (user_termios_to_kernel_termios + (&ap->termios, (struct termios __user *)argp)) + break; + err = 0; + break; + + /* Set DTR/RTS */ + case TIOCMBIS: + case TIOCMBIC: + /* Set exclusive/non-exclusive mode */ + case TIOCEXCL: + case TIOCNXCL: + DEBUG(FS_INFO, "TTY compatibility.\n"); + err = 0; + break; + + case TCGETA: + DEBUG(FS_INFO, "TCGETA\n"); + break; + + case TCFLSH: + DEBUG(FS_INFO, "TCFLSH\n"); + /* Note : this will flush buffers in PPP, so it *must* be done + * We should also worry that we don't accept junk here and that + * we get rid of our own buffers */ #ifdef FLUSH_TO_PPP - ppp_output_wakeup(&ap->chan); -#endif /* FLUSH_TO_PPP */ - err = 0; - break; - - case FIONREAD: - DEBUG(FS_INFO, "FIONREAD\n"); - val = 0; - if(put_user(val, (int __user *)argp)) - break; - err = 0; - break; - - default: - DERROR(FS_ERROR, "Unsupported ioctl (0x%X)\n", cmd); - err = -ENOIOCTLCMD; - } - - DEXIT(FS_TRACE, " - err = 0x%X\n", err); - return err; + ppp_output_wakeup(&ap->chan); +#endif /* FLUSH_TO_PPP */ + err = 0; + break; + + case FIONREAD: + DEBUG(FS_INFO, "FIONREAD\n"); + val = 0; + if (put_user(val, (int __user *)argp)) + break; + err = 0; + break; + + default: + DERROR(FS_ERROR, "Unsupported ioctl (0x%X)\n", cmd); + err = -ENOIOCTLCMD; + } + + DEXIT(FS_TRACE, " - err = 0x%X\n", err); + return err; } /************************** PPP CALLBACKS **************************/ @@ -798,66 +776,64 @@ dev_irnet_ioctl(struct inode * inode, * according to flags passed by pppd. * This is not a callback, but just a helper function used in ppp_irnet_send() */ -static inline struct sk_buff * -irnet_prepare_skb(irnet_socket * ap, - struct sk_buff * skb) +static inline struct sk_buff *irnet_prepare_skb(irnet_socket * ap, + struct sk_buff *skb) { - unsigned char * data; - int proto; /* PPP protocol */ - int islcp; /* Protocol == LCP */ - int needaddr; /* Need PPP address */ + unsigned char *data; + int proto; /* PPP protocol */ + int islcp; /* Protocol == LCP */ + int needaddr; /* Need PPP address */ - DENTER(PPP_TRACE, "(ap=0x%p, skb=0x%p)\n", - ap, skb); + DENTER(PPP_TRACE, "(ap=0x%p, skb=0x%p)\n", ap, skb); - /* Extract PPP protocol from the frame */ - data = skb->data; - proto = (data[0] << 8) + data[1]; + /* Extract PPP protocol from the frame */ + data = skb->data; + proto = (data[0] << 8) + data[1]; - /* LCP packets with codes between 1 (configure-request) - * and 7 (code-reject) must be sent as though no options - * have been negotiated. */ - islcp = (proto == PPP_LCP) && (1 <= data[2]) && (data[2] <= 7); + /* LCP packets with codes between 1 (configure-request) + * and 7 (code-reject) must be sent as though no options + * have been negotiated. */ + islcp = (proto == PPP_LCP) && (1 <= data[2]) && (data[2] <= 7); - /* compress protocol field if option enabled */ - if((data[0] == 0) && (ap->flags & SC_COMP_PROT) && (!islcp)) - skb_pull(skb,1); + /* compress protocol field if option enabled */ + if ((data[0] == 0) && (ap->flags & SC_COMP_PROT) && (!islcp)) + skb_pull(skb, 1); - /* Check if we need address/control fields */ - needaddr = 2*((ap->flags & SC_COMP_AC) == 0 || islcp); + /* Check if we need address/control fields */ + needaddr = 2 * ((ap->flags & SC_COMP_AC) == 0 || islcp); - /* Is the skb headroom large enough to contain all IrDA-headers? */ - if((skb_headroom(skb) < (ap->max_header_size + needaddr)) || - (skb_shared(skb))) - { - struct sk_buff * new_skb; + /* Is the skb headroom large enough to contain all IrDA-headers? */ + if ((skb_headroom(skb) < (ap->max_header_size + needaddr)) || + (skb_shared(skb))) { + struct sk_buff *new_skb; - DEBUG(PPP_INFO, "Reallocating skb\n"); + DEBUG(PPP_INFO, "Reallocating skb\n"); - /* Create a new skb */ - new_skb = skb_realloc_headroom(skb, ap->max_header_size + needaddr); + /* Create a new skb */ + new_skb = + skb_realloc_headroom(skb, ap->max_header_size + needaddr); - /* We have to free the original skb anyway */ - dev_kfree_skb(skb); + /* We have to free the original skb anyway */ + dev_kfree_skb(skb); - /* Did the realloc succeed ? */ - DABORT(new_skb == NULL, NULL, PPP_ERROR, "Could not realloc skb\n"); + /* Did the realloc succeed ? */ + DABORT(new_skb == NULL, NULL, PPP_ERROR, + "Could not realloc skb\n"); - /* Use the new skb instead */ - skb = new_skb; - } + /* Use the new skb instead */ + skb = new_skb; + } - /* prepend address/control fields if necessary */ - if(needaddr) - { - skb_push(skb, 2); - skb->data[0] = PPP_ALLSTATIONS; - skb->data[1] = PPP_UI; - } + /* prepend address/control fields if necessary */ + if (needaddr) { + skb_push(skb, 2); + skb->data[0] = PPP_ALLSTATIONS; + skb->data[1] = PPP_UI; + } - DEXIT(PPP_TRACE, "\n"); + DEXIT(PPP_TRACE, "\n"); - return skb; + return skb; } /*------------------------------------------------------------------*/ @@ -868,100 +844,101 @@ irnet_prepare_skb(irnet_socket * ap, * If the packet was not accepted, we will call ppp_output_wakeup * at some later time to reactivate flow control in ppp_generic. */ -static int -ppp_irnet_send(struct ppp_channel * chan, - struct sk_buff * skb) +static int ppp_irnet_send(struct ppp_channel *chan, struct sk_buff *skb) { - irnet_socket * self = (struct irnet_socket *) chan->private; - int ret; + irnet_socket *self = (struct irnet_socket *)chan->private; + int ret; - DENTER(PPP_TRACE, "(channel=0x%p, ap/self=0x%p)\n", - chan, self); + DENTER(PPP_TRACE, "(channel=0x%p, ap/self=0x%p)\n", chan, self); - /* Check if things are somewhat valid... */ - DASSERT(self != NULL, 0, PPP_ERROR, "Self is NULL !!!\n"); + /* Check if things are somewhat valid... */ + DASSERT(self != NULL, 0, PPP_ERROR, "Self is NULL !!!\n"); - /* Check if we are connected */ - if(!(test_bit(0, &self->ttp_open))) - { + /* Check if we are connected */ + if (!(test_bit(0, &self->ttp_open))) { #ifdef CONNECT_IN_SEND - /* Let's try to connect one more time... */ - /* Note : we won't be connected after this call, but we should be - * ready for next packet... */ - /* If we are already connecting, this will fail */ - irda_irnet_connect(self); -#endif /* CONNECT_IN_SEND */ - - DEBUG(PPP_INFO, "IrTTP not ready ! (%ld-%ld)\n", - self->ttp_open, self->ttp_connect); - - /* Note : we can either drop the packet or block the packet. - * - * Blocking the packet allow us a better connection time, - * because by calling ppp_output_wakeup() we can have - * ppp_generic resending the LCP request immediately to us, - * rather than waiting for one of pppd periodic transmission of ... [truncated message content] |