cregit-Linux how code gets into the kernel

Release 4.8 net/irda/af_irda.c

Directory: net/irda
/*********************************************************************
 *
 * Filename:      af_irda.c
 * Version:       0.9
 * Description:   IrDA sockets implementation
 * Status:        Stable
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Sun May 31 10:12:43 1998
 * Modified at:   Sat Dec 25 21:10:23 1999
 * Modified by:   Dag Brattli <dag@brattli.net>
 * Sources:       af_netroom.c, af_ax25.c, af_rose.c, af_x25.c etc.
 *
 *     Copyright (c) 1999 Dag Brattli <dagb@cs.uit.no>
 *     Copyright (c) 1999-2003 Jean Tourrilhes <jt@hpl.hp.com>
 *     All Rights Reserved.
 *
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
 *     the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, see <http://www.gnu.org/licenses/>.
 *
 *     Linux-IrDA now supports four different types of IrDA sockets:
 *
 *     o SOCK_STREAM:    TinyTP connections with SAR disabled. The
 *                       max SDU size is 0 for conn. of this type
 *     o SOCK_SEQPACKET: TinyTP connections with SAR enabled. TTP may
 *                       fragment the messages, but will preserve
 *                       the message boundaries
 *     o SOCK_DGRAM:     IRDAPROTO_UNITDATA: TinyTP connections with Unitdata
 *                       (unreliable) transfers
 *                       IRDAPROTO_ULTRA: Connectionless and unreliable data
 *
 ********************************************************************/

#include <linux/capability.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/net.h>
#include <linux/irda.h>
#include <linux/poll.h>

#include <asm/ioctls.h>		/* TIOCOUTQ, TIOCINQ */
#include <asm/uaccess.h>

#include <net/sock.h>
#include <net/tcp_states.h>

#include <net/irda/af_irda.h>

static int irda_create(struct net *net, struct socket *sock, int protocol, int kern);


static const struct proto_ops irda_stream_ops;

static const struct proto_ops irda_seqpacket_ops;

static const struct proto_ops irda_dgram_ops;

#ifdef CONFIG_IRDA_ULTRA

static const struct proto_ops irda_ultra_ops;

#define ULTRA_MAX_DATA 382
#endif /* CONFIG_IRDA_ULTRA */


#define IRDA_MAX_HEADER (TTP_MAX_HEADER)

/*
 * Function irda_data_indication (instance, sap, skb)
 *
 *    Received some data from TinyTP. Just queue it on the receive queue
 *
 */

static int irda_data_indication(void *instance, void *sap, struct sk_buff *skb) { struct irda_sock *self; struct sock *sk; int err; self = instance; sk = instance; err = sock_queue_rcv_skb(sk, skb); if (err) { pr_debug("%s(), error: no more mem!\n", __func__); self->rx_flow = FLOW_STOP; /* When we return error, TTP will need to requeue the skb */ return err; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7093.33%233.33%
jean tourrilhesjean tourrilhes22.67%116.67%
joe perchesjoe perches11.33%116.67%
harvey harrisonharvey harrison11.33%116.67%
arnaldo carvalho de meloarnaldo carvalho de melo11.33%116.67%
Total75100.00%6100.00%

/* * Function irda_disconnect_indication (instance, sap, reason, skb) * * Connection has been closed. Check reason to find out why * */
static void irda_disconnect_indication(void *instance, void *sap, LM_REASON reason, struct sk_buff *skb) { struct irda_sock *self; struct sock *sk; self = instance; pr_debug("%s(%p)\n", __func__, self); /* Don't care about it, but let's not leak it */ if(skb) dev_kfree_skb(skb); sk = instance; if (sk == NULL) { pr_debug("%s(%p) : BUG : sk is NULL\n", __func__, self); return; } /* Prevent race conditions with irda_release() and irda_shutdown() */ bh_lock_sock(sk); if (!sock_flag(sk, SOCK_DEAD) && sk->sk_state != TCP_CLOSE) { sk->sk_state = TCP_CLOSE; sk->sk_shutdown |= SEND_SHUTDOWN; sk->sk_state_change(sk); /* Close our TSAP. * If we leave it open, IrLMP put it back into the list of * unconnected LSAPs. The problem is that any incoming request * can then be matched to this socket (and it will be, because * it is at the head of the list). This would prevent any * listening socket waiting on the same TSAP to get those * requests. Some apps forget to close sockets, or hang to it * a bit too long, so we may stay in this dead state long * enough to be noticed... * Note : all socket function do check sk->sk_state, so we are * safe... * Jean II */ if (self->tsap) { irttp_close_tsap(self->tsap); self->tsap = NULL; } } bh_unlock_sock(sk); /* Note : once we are there, there is not much you want to do * with the socket anymore, apart from closing it. * For example, bind() and connect() won't reset sk->sk_err, * sk->sk_shutdown and sk->sk_flags to valid values... * Jean II */ }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7550.68%426.67%
linus torvaldslinus torvalds3624.32%213.33%
jean tourrilhesjean tourrilhes117.43%213.33%
olaf kircholaf kirch106.76%16.67%
arnaldo carvalho de meloarnaldo carvalho de melo106.76%320.00%
joe perchesjoe perches21.35%16.67%
james morrisjames morris21.35%16.67%
harvey harrisonharvey harrison21.35%16.67%
Total148100.00%15100.00%

/* * Function irda_connect_confirm (instance, sap, qos, max_sdu_size, skb) * * Connections has been confirmed by the remote device * */
static void irda_connect_confirm(void *instance, void *sap, struct qos_info *qos, __u32 max_sdu_size, __u8 max_header_size, struct sk_buff *skb) { struct irda_sock *self; struct sock *sk; self = instance; pr_debug("%s(%p)\n", __func__, self); sk = instance; if (sk == NULL) { dev_kfree_skb(skb); return; } dev_kfree_skb(skb); // Should be ??? skb_queue_tail(&sk->sk_receive_queue, skb); /* How much header space do we need to reserve */ self->max_header_size = max_header_size; /* IrTTP max SDU size in transmit direction */ self->max_sdu_size_tx = max_sdu_size; /* Find out what the largest chunk of data that we can transmit is */ switch (sk->sk_type) { case SOCK_STREAM: if (max_sdu_size != 0) { net_err_ratelimited("%s: max_sdu_size must be 0\n", __func__); return; } self->max_data_size = irttp_get_max_seg_size(self->tsap); break; case SOCK_SEQPACKET: if (max_sdu_size == 0) { net_err_ratelimited("%s: max_sdu_size cannot be 0\n", __func__); return; } self->max_data_size = max_sdu_size; break; default: self->max_data_size = irttp_get_max_seg_size(self->tsap); } pr_debug("%s(), max_data_size=%d\n", __func__, self->max_data_size); memcpy(&self->qos_tx, qos, sizeof(struct qos_info)); /* We are now connected! */ sk->sk_state = TCP_ESTABLISHED; sk->sk_state_change(sk); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git17281.90%637.50%
jean tourrilhesjean tourrilhes167.62%318.75%
arnaldo carvalho de meloarnaldo carvalho de melo52.38%212.50%
linus torvaldslinus torvalds52.38%16.25%
martin daleckimartin dalecki41.90%16.25%
harvey harrisonharvey harrison41.90%16.25%
joe perchesjoe perches41.90%212.50%
Total210100.00%16100.00%

/* * Function irda_connect_indication(instance, sap, qos, max_sdu_size, userdata) * * Incoming connection * */
static void irda_connect_indication(void *instance, void *sap, struct qos_info *qos, __u32 max_sdu_size, __u8 max_header_size, struct sk_buff *skb) { struct irda_sock *self; struct sock *sk; self = instance; pr_debug("%s(%p)\n", __func__, self); sk = instance; if (sk == NULL) { dev_kfree_skb(skb); return; } /* How much header space do we need to reserve */ self->max_header_size = max_header_size; /* IrTTP max SDU size in transmit direction */ self->max_sdu_size_tx = max_sdu_size; /* Find out what the largest chunk of data that we can transmit is */ switch (sk->sk_type) { case SOCK_STREAM: if (max_sdu_size != 0) { net_err_ratelimited("%s: max_sdu_size must be 0\n", __func__); kfree_skb(skb); return; } self->max_data_size = irttp_get_max_seg_size(self->tsap); break; case SOCK_SEQPACKET: if (max_sdu_size == 0) { net_err_ratelimited("%s: max_sdu_size cannot be 0\n", __func__); kfree_skb(skb); return; } self->max_data_size = max_sdu_size; break; default: self->max_data_size = irttp_get_max_seg_size(self->tsap); } pr_debug("%s(), max_data_size=%d\n", __func__, self->max_data_size); memcpy(&self->qos_tx, qos, sizeof(struct qos_info)); skb_queue_tail(&sk->sk_receive_queue, skb); sk->sk_state_change(sk); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git17580.65%637.50%
jean tourrilhesjean tourrilhes219.68%318.75%
linus torvaldslinus torvalds52.30%16.25%
harvey harrisonharvey harrison41.84%16.25%
martin daleckimartin dalecki41.84%16.25%
arnaldo carvalho de meloarnaldo carvalho de melo41.84%212.50%
joe perchesjoe perches41.84%212.50%
Total217100.00%16100.00%

/* * Function irda_connect_response (handle) * * Accept incoming connection * */
static void irda_connect_response(struct irda_sock *self) { struct sk_buff *skb; skb = alloc_skb(TTP_MAX_HEADER + TTP_SAR_HEADER, GFP_KERNEL); if (skb == NULL) { pr_debug("%s() Unable to allocate sk_buff!\n", __func__); return; } /* Reserve space for MUX_CONTROL and LAP header */ skb_reserve(skb, IRDA_MAX_HEADER); irttp_connect_response(self->tsap, self->max_sdu_size_rx, skb); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5382.81%436.36%
samuel ortizsamuel ortiz57.81%218.18%
jean tourrilhesjean tourrilhes23.12%19.09%
mathias krausemathias krause11.56%19.09%
harvey harrisonharvey harrison11.56%19.09%
adrian bunkadrian bunk11.56%19.09%
joe perchesjoe perches11.56%19.09%
Total64100.00%11100.00%

/* * Function irda_flow_indication (instance, sap, flow) * * Used by TinyTP to tell us if it can accept more data or not * */
static void irda_flow_indication(void *instance, void *sap, LOCAL_FLOW flow) { struct irda_sock *self; struct sock *sk; self = instance; sk = instance; BUG_ON(sk == NULL); switch (flow) { case FLOW_STOP: pr_debug("%s(), IrTTP wants us to slow down\n", __func__); self->tx_flow = flow; break; case FLOW_START: self->tx_flow = flow; pr_debug("%s(), IrTTP wants us to start again\n", __func__); wake_up_interruptible(sk_sleep(sk)); break; default: pr_debug("%s(), Unknown flow command!\n", __func__); /* Unknown flow command, better stop */ self->tx_flow = flow; break; } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8479.25%330.00%
jean tourrilhesjean tourrilhes65.66%110.00%
samuel ortizsamuel ortiz54.72%110.00%
eric dumazeteric dumazet32.83%110.00%
harvey harrisonharvey harrison32.83%110.00%
joe perchesjoe perches32.83%110.00%
arnaldo carvalho de meloarnaldo carvalho de melo21.89%220.00%
Total106100.00%10100.00%

/* * Function irda_getvalue_confirm (obj_id, value, priv) * * Got answer from remote LM-IAS, just pass object to requester... * * Note : duplicate from above, but we need our own version that * doesn't touch the dtsap_sel and save the full value structure... */
static void irda_getvalue_confirm(int result, __u16 obj_id, struct ias_value *value, void *priv) { struct irda_sock *self; self = priv; if (!self) { net_warn_ratelimited("%s: lost myself!\n", __func__); return; } pr_debug("%s(%p)\n", __func__, self); /* We probably don't need to make any more queries */ iriap_close(self->iriap); self->iriap = NULL; /* Check if request succeeded */ if (result != IAS_SUCCESS) { pr_debug("%s(), IAS query failed! (%d)\n", __func__, result); self->errno = result; /* We really need it later */ /* Wake up any processes waiting for result */ wake_up_interruptible(&self->query_wait); return; } /* Pass the object to the caller (so the caller must delete it) */ self->ias_result = value; self->errno = 0; /* Wake up any processes waiting for result */ wake_up_interruptible(&self->query_wait); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10886.40%753.85%
linus torvaldslinus torvalds54.00%17.69%
jean tourrilhesjean tourrilhes43.20%17.69%
harvey harrisonharvey harrison32.40%17.69%
joe perchesjoe perches32.40%215.38%
martin daleckimartin dalecki21.60%17.69%
Total125100.00%13100.00%

/* * Function irda_selective_discovery_indication (discovery) * * Got a selective discovery indication from IrLMP. * * IrLMP is telling us that this node is new and matching our hint bit * filter. Wake up any process waiting for answer... */
static void irda_selective_discovery_indication(discinfo_t *discovery, DISCOVERY_MODE mode, void *priv) { struct irda_sock *self; self = priv; if (!self) { net_warn_ratelimited("%s: lost myself!\n", __func__); return; } /* Pass parameter to the caller */ self->cachedaddr = discovery->daddr; /* Wake up process if its waiting for device to be discovered */ wake_up_interruptible(&self->query_wait); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4881.36%337.50%
jean tourrilhesjean tourrilhes711.86%225.00%
martin daleckimartin dalecki23.39%112.50%
harvey harrisonharvey harrison11.69%112.50%
joe perchesjoe perches11.69%112.50%
Total59100.00%8100.00%

/* * Function irda_discovery_timeout (priv) * * Timeout in the selective discovery process * * We were waiting for a node to be discovered, but nothing has come up * so far. Wake up the user and tell him that we failed... */
static void irda_discovery_timeout(u_long priv) { struct irda_sock *self; self = (struct irda_sock *) priv; BUG_ON(self == NULL); /* Nothing for the caller */ self->cachelog = NULL; self->cachedaddr = 0; self->errno = -ETIME; /* Wake up process if its still waiting... */ wake_up_interruptible(&self->query_wait); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5288.14%250.00%
samuel ortizsamuel ortiz58.47%125.00%
jean tourrilhesjean tourrilhes23.39%125.00%
Total59100.00%4100.00%

/* * Function irda_open_tsap (self) * * Open local Transport Service Access Point (TSAP) * */
static int irda_open_tsap(struct irda_sock *self, __u8 tsap_sel, char *name) { notify_t notify; if (self->tsap) { pr_debug("%s: busy!\n", __func__); return -EBUSY; } /* Initialize callbacks to be used by the IrDA stack */ irda_notify_init(&notify); notify.connect_confirm = irda_connect_confirm; notify.connect_indication = irda_connect_indication; notify.disconnect_indication = irda_disconnect_indication; notify.data_indication = irda_data_indication; notify.udata_indication = irda_data_indication; notify.flow_indication = irda_flow_indication; notify.instance = self; strncpy(notify.name, name, NOTIFY_MAX_NAME); self->tsap = irttp_open_tsap(tsap_sel, DEFAULT_INITIAL_CREDIT, &notify); if (self->tsap == NULL) { pr_debug("%s(), Unable to allocate TSAP!\n", __func__); return -ENOMEM; } /* Remember which TSAP selector we actually got */ self->stsap_sel = self->tsap->stsap_sel; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git14194.63%342.86%
jean tourrilhesjean tourrilhes21.34%114.29%
joe perchesjoe perches21.34%114.29%
harvey harrisonharvey harrison21.34%114.29%
martin daleckimartin dalecki21.34%114.29%
Total149100.00%7100.00%

/* * Function irda_open_lsap (self) * * Open local Link Service Access Point (LSAP). Used for opening Ultra * sockets */ #ifdef CONFIG_IRDA_ULTRA
static int irda_open_lsap(struct irda_sock *self, int pid) { notify_t notify; if (self->lsap) { net_warn_ratelimited("%s(), busy!\n", __func__); return -EBUSY; } /* Initialize callbacks to be used by the IrDA stack */ irda_notify_init(&notify); notify.udata_indication = irda_data_indication; notify.instance = self; strncpy(notify.name, "Ultra", NOTIFY_MAX_NAME); self->lsap = irlmp_open_lsap(LSAP_CONNLESS, &notify, pid); if (self->lsap == NULL) { pr_debug("%s(), Unable to allocate LSAP!\n", __func__); return -ENOMEM; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git9692.31%342.86%
jeff garzikjeff garzik43.85%114.29%
harvey harrisonharvey harrison21.92%114.29%
joe perchesjoe perches21.92%228.57%
Total104100.00%7100.00%

#endif /* CONFIG_IRDA_ULTRA */ /* * Function irda_find_lsap_sel (self, name) * * Try to lookup LSAP selector in remote LM-IAS * * Basically, we start a IAP query, and then go to sleep. When the query * return, irda_getvalue_confirm will wake us up, and we can examine the * result of the query... * Note that in some case, the query fail even before we go to sleep, * creating some races... */
static int irda_find_lsap_sel(struct irda_sock *self, char *name) { pr_debug("%s(%p, %s)\n", __func__, self, name); if (self->iriap) { net_warn_ratelimited("%s(): busy with a previous query\n", __func__); return -EBUSY; } self->iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self, irda_getvalue_confirm); if(self->iriap == NULL) return -ENOMEM; /* Treat unexpected wakeup as disconnect */ self->errno = -EHOSTUNREACH; /* Query remote LM-IAS */ iriap_getvaluebyclass_request(self->iriap, self->saddr, self->daddr, name, "IrDA:TinyTP:LsapSel"); /* Wait for answer, if not yet finished (or failed) */ if (wait_event_interruptible(self->query_wait, (self->iriap==NULL))) /* Treat signals as disconnect */ return -EHOSTUNREACH; /* Check what happened */ if (self->errno) { /* Requested object/attribute doesn't exist */ if((self->errno == IAS_CLASS_UNKNOWN) || (self->errno == IAS_ATTRIB_UNKNOWN)) return -EADDRNOTAVAIL; else return -EHOSTUNREACH; } /* Get the remote TSAP selector */ switch (self->ias_result->type) { case IAS_INTEGER: pr_debug("%s() int=%d\n", __func__, self->ias_result->t.integer); if (self->ias_result->t.integer != -1) self->dtsap_sel = self->ias_result->t.integer; else self->dtsap_sel = 0; break; default: self->dtsap_sel = 0; pr_debug("%s(), bad type!\n", __func__); break; } if (self->ias_result) irias_delete_value(self->ias_result); if (self->dtsap_sel) return 0; return -EADDRNOTAVAIL; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git21682.13%541.67%
jean tourrilhesjean tourrilhes176.46%18.33%
linus torvaldslinus torvalds145.32%18.33%
jeff garzikjeff garzik72.66%18.33%
joe perchesjoe perches41.52%216.67%
harvey harrisonharvey harrison41.52%18.33%
martin daleckimartin dalecki10.38%18.33%
Total263100.00%12100.00%

/* * Function irda_discover_daddr_and_lsap_sel (self, name) * * This try to find a device with the requested service. * * It basically look into the discovery log. For each address in the list, * it queries the LM-IAS of the device to find if this device offer * the requested service. * If there is more than one node supporting the service, we complain * to the user (it should move devices around). * The, we set both the destination address and the lsap selector to point * on the service on the unique device we have found. * * Note : this function fails if there is more than one device in range, * because IrLMP doesn't disconnect the LAP when the last LSAP is closed. * Moreover, we would need to wait the LAP disconnection... */
static int irda_discover_daddr_and_lsap_sel(struct irda_sock *self, char *name) { discinfo_t *discoveries; /* Copy of the discovery log */ int number; /* Number of nodes in the log */ int i; int err = -ENETUNREACH; __u32 daddr = DEV_ADDR_ANY; /* Address we found the service on */ __u8 dtsap_sel = 0x0; /* TSAP associated with it */ pr_debug("%s(), name=%s\n", __func__, name); /* Ask lmp for the current discovery log * Note : we have to use irlmp_get_discoveries(), as opposed * to play with the cachelog directly, because while we are * making our ias query, le log might change... */ discoveries = irlmp_get_discoveries(&number, self->mask.word, self->nslots); /* Check if the we got some results */ if (discoveries == NULL) return -ENETUNREACH; /* No nodes discovered */ /* * Now, check all discovered devices (if any), and connect * client only about the services that the client is * interested in... */ for(i = 0; i < number; i++) { /* Try the address in the log */ self->daddr = discoveries[i].daddr; self->saddr = 0x0; pr_debug("%s(), trying daddr = %08x\n", __func__, self->daddr); /* Query remote LM-IAS for this service */ err = irda_find_lsap_sel(self, name); switch (err) { case 0: /* We found the requested service */ if(daddr != DEV_ADDR_ANY) { pr_debug("%s(), discovered service ''%s'' in two different devices !!!\n", __func__, name); self->daddr = DEV_ADDR_ANY; kfree(discoveries); return -ENOTUNIQ; } /* First time we found that one, save it ! */ daddr = self->daddr; dtsap_sel = self->dtsap_sel; break; case -EADDRNOTAVAIL: /* Requested service simply doesn't exist on this node */ break; default: /* Something bad did happen :-( */ pr_debug("%s(), unexpected IAS query failure\n", __func__); self->daddr = DEV_ADDR_ANY; kfree(discoveries); return -EHOSTUNREACH; } } /* Cleanup our copy of the discovery log */ kfree(discoveries); /* Check out what we found */ if(daddr == DEV_ADDR_ANY) { pr_debug("%s(), cannot discover service ''%s'' in any device !!!\n", __func__, name); self->daddr = DEV_ADDR_ANY; return -EADDRNOTAVAIL; } /* Revert back to discovered device & service */ self->daddr = daddr; self->saddr = 0x0; self->dtsap_sel = dtsap_sel; pr_debug("%s(), discovered requested service ''%s'' at address %08x\n", __func__, name, self->daddr); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git26389.15%333.33%
jeff garzikjeff garzik124.07%111.11%
joe perchesjoe perches62.03%111.11%
harvey harrisonharvey harrison62.03%111.11%
linus torvaldslinus torvalds41.36%111.11%
jean tourrilhesjean tourrilhes31.02%111.11%
martin daleckimartin dalecki10.34%111.11%
Total295100.00%9100.00%

/* * Function irda_getname (sock, uaddr, uaddr_len, peer) * * Return the our own, or peers socket address (sockaddr_irda) * */
static int irda_getname(struct socket *sock, struct sockaddr *uaddr, int *uaddr_len, int peer) { struct sockaddr_irda saddr; struct sock *sk = sock->sk; struct irda_sock *self = irda_sk(sk); memset(&saddr, 0, sizeof(saddr)); if (peer) { if (sk->sk_state != TCP_ESTABLISHED) return -ENOTCONN; saddr.sir_family = AF_IRDA; saddr.sir_lsap_sel = self->dtsap_sel; saddr.sir_addr = self->daddr; } else { saddr.sir_family = AF_IRDA; saddr.sir_lsap_sel = self->stsap_sel; saddr.sir_addr = self->saddr; } pr_debug("%s(), tsap_sel = %#x\n", __func__, saddr.sir_lsap_sel); pr_debug("%s(), addr = %08x\n", __func__, saddr.sir_addr); /* uaddr_len come to us uninitialised */ *uaddr_len = sizeof (struct sockaddr_irda); memcpy(uaddr, &saddr, *uaddr_len); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git13981.76%327.27%
eric dumazeteric dumazet137.65%19.09%
samuel ortizsamuel ortiz52.94%19.09%
jeff garzikjeff garzik42.35%19.09%
david s. millerdavid s. miller31.76%19.09%
joe perchesjoe perches21.18%19.09%
harvey harrisonharvey harrison21.18%19.09%
arnd bergmannarnd bergmann10.59%19.09%
arnaldo carvalho de meloarnaldo carvalho de melo10.59%19.09%
Total170100.00%11100.00%

/* * Function irda_listen (sock, backlog) * * Just move to the listen state * */
static int irda_listen(struct socket *sock, int backlog) { struct sock *sk = sock->sk; int err = -EOPNOTSUPP; lock_sock(sk); if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) && (sk->sk_type != SOCK_DGRAM)) goto out; if (sk->sk_state != TCP_LISTEN) { sk->sk_max_ack_backlog = backlog; sk->sk_state = TCP_LISTEN; err = 0; } out: release_sock(sk); return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git6868.69%240.00%
arnd bergmannarnd bergmann1717.17%120.00%
samuel ortizsamuel ortiz88.08%120.00%
arnaldo carvalho de meloarnaldo carvalho de melo66.06%120.00%
Total99100.00%5100.00%

/* * Function irda_bind (sock, uaddr, addr_len) * * Used by servers to register their well known TSAP * */
static int irda_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len) { struct sock *sk = sock->sk; struct sockaddr_irda *addr = (struct sockaddr_irda *) uaddr; struct irda_sock *self = irda_sk(sk); int err; pr_debug("%s(%p)\n", __func__, self); if (addr_len != sizeof(struct sockaddr_irda)) return -EINVAL; lock_sock(sk); #ifdef CONFIG_IRDA_ULTRA /* Special care for Ultra sockets */ if ((sk->sk_type == SOCK_DGRAM) && (sk->sk_protocol == IRDAPROTO_ULTRA)) { self->pid = addr->sir_lsap_sel; err = -EOPNOTSUPP; if (self->pid & 0x80) { pr_debug("%s(), extension in PID not supp!\n", __func__); goto out; } err = irda_open_lsap(self, self->pid); if (err < 0) goto out; /* Pretend we are connected */ sock->state = SS_CONNECTED; sk->sk_state = TCP_ESTABLISHED; err = 0; goto out; } #endif /* CONFIG_IRDA_ULTRA */ self->ias_obj = irias_new_object(addr->sir_name, jiffies); err = -ENOMEM; if (self->ias_obj == NULL) goto out; err = irda_open_tsap(self, addr->sir_lsap_sel, addr->sir_name); if (err < 0) { irias_delete_object(self->ias_obj); self->ias_obj = NULL; goto out; } /* Register with LM-IAS */ irias_add_integer_attrib(self->ias_obj, "IrDA:TinyTP:LsapSel", self->stsap_sel, IAS_KERNEL_ATTR); irias_insert_object(self->ias_obj); err = 0; out: release_sock(sk); return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git18865.73%323.08%
arnd bergmannarnd bergmann3712.94%17.69%
jesper juhljesper juhl2910.14%17.69%
samuel ortizsamuel ortiz82.80%17.69%
david s. millerdavid s. miller82.80%215.38%
linus torvaldslinus torvalds51.75%17.69%
jeff garzikjeff garzik41.40%17.69%
arnaldo carvalho de meloarnaldo carvalho de melo31.05%17.69%
harvey harrisonharvey harrison20.70%17.69%
joe perchesjoe perches20.70%17.69%
Total286100.00%13100.00%

/* * Function irda_accept (sock, newsock, flags) * * Wait for incoming connection * */
static int irda_accept(struct socket *sock, struct socket *newsock, int flags) { struct sock *sk = sock->sk; struct irda_sock *new, *self = irda_sk(sk); struct sock *newsk; struct sk_buff *skb = NULL; int err; err = irda_create(sock_net(sk), newsock, sk->sk_protocol, 0); if (err) return err; err = -EINVAL; lock_sock(sk); if (sock->state != SS_UNCONNECTED) goto out; if ((sk = sock->sk) == NULL) goto out; err = -EOPNOTSUPP; if ((sk->sk_type != SOCK_STREAM) && (sk->sk_type != SOCK_SEQPACKET) && (sk->sk_type != SOCK_DGRAM)) goto out; err = -EINVAL; if (sk->sk_state != TCP_LISTEN) goto out; /* * The read queue this time is holding sockets ready to use * hooked into the SABM we saved */ /* * We can perform the accept only if there is incoming data * on the listening socket. * So, we will block the caller until we receive any data. * If the caller was waiting on select() or poll() before * calling us, the data is waiting for us ;-) * Jean II */ while (1) { skb = skb_dequeue(&sk->sk_receive_queue); if (skb) break; /* Non blocking operation */ err = -EWOULDBLOCK; if (flags & O_NONBLOCK) goto out; err = wait_event_interruptible(*(sk_sleep(sk)), skb_peek(&sk->sk_receive_queue)); if (err) goto out; } newsk = newsock->sk; err = -EIO; if (newsk == NULL) goto out; newsk->sk_state = TCP_ESTABLISHED; new = irda_sk(newsk); /* Now attach up the new socket */ new->tsap = irttp_dup(self->tsap, new); err = -EPERM; /* value does not seem to make sense. -arnd */ if (!new->tsap) { pr_debug("%s(), dup failed!\n", __func__); goto out; } new->stsap_sel = new->tsap->stsap_sel; new->dtsap_sel = new->tsap->dtsap_sel; new->saddr = irttp_get_saddr(new->tsap); new->daddr = irttp_get_daddr(new->tsap); new->max_sdu_size_tx = self->max_sdu_size_tx; new->max_sdu_size_rx = self->max_sdu_size_rx; new->max_data_size = self->max_data_size; new->max_header_size = self->max_header_size; memcpy(&new->qos_tx, &self->qos_tx, sizeof(struct qos_info)); /* Clean up the original one to keep it in listen state */ irttp_listen(self->tsap); sk->sk_ack_backlog--; newsock->state = SS_CONNECTED; irda_connect_response(new); err = 0; out: kfree_skb(skb); release_sock(sk); return err; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git28464.40%419.05%
arnd bergmannarnd bergmann6013.61%14.76%
samuel ortizsamuel ortiz327.26%314.29%
david s. millerdavid s. miller163.63%14.76%
jean tourrilhesjean tourrilhes143.17%14.76%
arnaldo carvalho de meloarnaldo carvalho de melo102.27%14.76%
phil turnbullphil turnbull71.59%14.76%
eric dumazeteric dumazet30.68%14.76%
hideaki yoshifujihideaki yoshifuji30.68%14.76%
linus torvaldslinus torvalds30.68%14.76%
eric w. biedermaneric w. biederman20.45%14.76%
jeff garzikjeff garzik20.45%14.76%
eric pariseric paris20.45%14.76%
steven colesteven cole10.23%14.76%
harvey harrisonharvey harrison10.23%14.76%
joe perchesjoe perches10.23%14.76%
Total441100.00%21100.00%

/* * Function irda_connect (sock, uaddr, addr_len, flags) * * Connect to a IrDA device * * The main difference with a "standard" connect is that with IrDA we need * to resolve the service name into a TSAP selector (in TCP, port number * doesn't have to be resolved). * Because of this service name resolution, we can offer "auto-connect", * where we connect to a service without specifying a destination address. * * Note : by consulting "errno", the user space caller may learn the cause * of the failure. Most of them are visible in the function, others may come * from subroutines called and are listed here : * o EBUSY : already processing a connect * o EHOSTUNREACH : bad addr->sir_addr argument * o EADDRNOTAVAIL : bad addr->sir_name argument * o ENOTUNIQ : more than one node has addr->sir_name (auto-connect) * o ENETUNREACH : no node found on the network (auto-connect) */
static int irda_connect(struct socket *sock, struct sockaddr *uaddr, int addr_len, int flags) { struct sock *sk = sock->sk; struct sockaddr_irda *addr = (struct sockaddr_irda *) uaddr; struct irda_sock *self = irda_sk(sk); int err; pr_debug("%s(%p)\n", __func__, self); lock_sock(sk); /* Don't allow connect for Ultra sockets */ err = -ESOCKTNOSUPPORT; if ((sk->sk_type == SOCK_DGRAM) && (sk->sk_protocol == IRDAPROTO_ULTRA)) goto out; if (sk->sk_state == TCP_ESTABLISHED && sock->state