cregit-Linux how code gets into the kernel

Release 4.8 net/irda/irlap.c

Directory: net/irda
/*********************************************************************
 *
 * Filename:      irlap.c
 * Version:       1.0
 * Description:   IrLAP implementation for Linux
 * Status:        Stable
 * Author:        Dag Brattli <dagb@cs.uit.no>
 * Created at:    Mon Aug  4 20:40:53 1997
 * Modified at:   Tue Dec 14 09:26:44 1999
 * Modified by:   Dag Brattli <dagb@cs.uit.no>
 *
 *     Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
 *     Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
 *
 *     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/>.
 *
 ********************************************************************/

#include <linux/slab.h>
#include <linux/string.h>
#include <linux/skbuff.h>
#include <linux/delay.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/random.h>
#include <linux/module.h>
#include <linux/seq_file.h>

#include <net/irda/irda.h>
#include <net/irda/irda_device.h>
#include <net/irda/irqueue.h>
#include <net/irda/irlmp.h>
#include <net/irda/irlmp_frame.h>
#include <net/irda/irlap_frame.h>
#include <net/irda/irlap.h>
#include <net/irda/timer.h>
#include <net/irda/qos.h>


static hashbin_t *irlap = NULL;

int sysctl_slot_timeout = SLOT_TIMEOUT * 1000 / HZ;

/* This is the delay of missed pf period before generating an event
 * to the application. The spec mandate 3 seconds, but in some cases
 * it's way too long. - Jean II */

int sysctl_warn_noreply_time = 3;

extern void irlap_queue_xmit(struct irlap_cb *self, struct sk_buff *skb);
static void __irlap_close(struct irlap_cb *self);
static void irlap_init_qos_capabilities(struct irlap_cb *self,
					struct qos_info *qos_user);


static const char *const lap_reasons[] __maybe_unused = {
	"ERROR, NOT USED",
	"LAP_DISC_INDICATION",
	"LAP_NO_RESPONSE",
	"LAP_RESET_INDICATION",
	"LAP_FOUND_NONE",
	"LAP_MEDIA_BUSY",
	"LAP_PRIMARY_CONFLICT",
	"ERROR, NOT USED",
};


int __init irlap_init(void) { /* Check if the compiler did its job properly. * May happen on some ARM configuration, check with Russell King. */ IRDA_ASSERT(sizeof(struct xid_frame) == 14, ;); IRDA_ASSERT(sizeof(struct test_frame) == 10, ;); IRDA_ASSERT(sizeof(struct ua_frame) == 10, ;); IRDA_ASSERT(sizeof(struct snrm_frame) == 11, ;); /* Allocate master array */ irlap = hashbin_new(HB_LOCK); if (irlap == NULL) { net_err_ratelimited("%s: can't allocate irlap hashbin!\n", __func__); return -ENOMEM; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
jean tourrilhesjean tourrilhes3447.89%337.50%
pre-gitpre-git3346.48%225.00%
martin daleckimartin dalecki22.82%112.50%
harvey harrisonharvey harrison11.41%112.50%
joe perchesjoe perches11.41%112.50%
Total71100.00%8100.00%


void irlap_cleanup(void) { IRDA_ASSERT(irlap != NULL, return;); hashbin_delete(irlap, (FREE_FUNC) __irlap_close); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git2395.83%150.00%
jean tourrilhesjean tourrilhes14.17%150.00%
Total24100.00%2100.00%

/* * Function irlap_open (driver) * * Initialize IrLAP layer * */
struct irlap_cb *irlap_open(struct net_device *dev, struct qos_info *qos, const char *hw_name) { struct irlap_cb *self; /* Initialize the irlap structure. */ self = kzalloc(sizeof(struct irlap_cb), GFP_KERNEL); if (self == NULL) return NULL; self->magic = LAP_MAGIC; /* Make a binding between the layers */ self->netdev = dev; self->qos_dev = qos; /* Copy hardware name */ if(hw_name != NULL) { strlcpy(self->hw_name, hw_name, sizeof(self->hw_name)); } else { self->hw_name[0] = '\0'; } /* FIXME: should we get our own field? */ dev->atalk_ptr = self; self->state = LAP_OFFLINE; /* Initialize transmit queue */ skb_queue_head_init(&self->txq); skb_queue_head_init(&self->txq_ultra); skb_queue_head_init(&self->wx_list); /* My unique IrLAP device address! */ /* We don't want the broadcast address, neither the NULL address * (most often used to signify "invalid"), and we don't want an * address already in use (otherwise connect won't be able * to select the proper link). - Jean II */ do { get_random_bytes(&self->saddr, sizeof(self->saddr)); } while ((self->saddr == 0x0) || (self->saddr == BROADCAST) || (hashbin_lock_find(irlap, self->saddr, NULL)) ); /* Copy to the driver */ memcpy(dev->dev_addr, &self->saddr, 4); init_timer(&self->slot_timer); init_timer(&self->query_timer); init_timer(&self->discovery_timer); init_timer(&self->final_timer); init_timer(&self->poll_timer); init_timer(&self->wd_timer); init_timer(&self->backoff_timer); init_timer(&self->media_busy_timer); irlap_apply_default_connection_parameters(self); self->N3 = 3; /* # connections attempts to try before giving up */ self->state = LAP_NDM; hashbin_insert(irlap, (irda_queue_t *) self, self->saddr, NULL); irlmp_register_link(self, self->saddr, &self->notify); return self; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git24073.39%746.67%
jean tourrilhesjean tourrilhes4313.15%320.00%
linus torvaldslinus torvalds3611.01%16.67%
ben collinsben collins51.53%16.67%
panagiotis issaris*panagiotis issaris*10.31%16.67%
stephen hemmingerstephen hemminger10.31%16.67%
lucas de marchilucas de marchi10.31%16.67%
Total327100.00%15100.00%

EXPORT_SYMBOL(irlap_open); /* * Function __irlap_close (self) * * Remove IrLAP and all allocated memory. Stop any pending timers. * */
static void __irlap_close(struct irlap_cb *self) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* Stop timers */ del_timer(&self->slot_timer); del_timer(&self->query_timer); del_timer(&self->discovery_timer); del_timer(&self->final_timer); del_timer(&self->poll_timer); del_timer(&self->wd_timer); del_timer(&self->backoff_timer); del_timer(&self->media_busy_timer); irlap_flush_all_queues(self); self->magic = 0; kfree(self); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10498.11%375.00%
jean tourrilhesjean tourrilhes21.89%125.00%
Total106100.00%4100.00%

/* * Function irlap_close (self) * * Remove IrLAP instance * */
void irlap_close(struct irlap_cb *self) { struct irlap_cb *lap; IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* We used to send a LAP_DISC_INDICATION here, but this was * racy. This has been move within irlmp_unregister_link() * itself. Jean II */ /* Kill the LAP and all LSAPs on top of it */ irlmp_unregister_link(self->saddr); self->notify.instance = NULL; /* Be sure that we manage to remove ourself from the hash */ lap = hashbin_remove(irlap, self->saddr, NULL); if (!lap) { pr_debug("%s(), Didn't find myself!\n", __func__); return; } __irlap_close(lap); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7290.00%228.57%
jean tourrilhesjean tourrilhes67.50%342.86%
joe perchesjoe perches11.25%114.29%
harvey harrisonharvey harrison11.25%114.29%
Total80100.00%7100.00%

EXPORT_SYMBOL(irlap_close); /* * Function irlap_connect_indication (self, skb) * * Another device is attempting to make a connection * */
void irlap_connect_indication(struct irlap_cb *self, struct sk_buff *skb) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); irlap_init_qos_capabilities(self, NULL); /* No user QoS! */ irlmp_link_connect_indication(self->notify.instance, self->saddr, self->daddr, &self->qos_tx, skb); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5996.72%266.67%
jean tourrilhesjean tourrilhes23.28%133.33%
Total61100.00%3100.00%

/* * Function irlap_connect_response (self, skb) * * Service user has accepted incoming connection * */
void irlap_connect_response(struct irlap_cb *self, struct sk_buff *userdata) { irlap_do_event(self, CONNECT_RESPONSE, userdata, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git2492.31%150.00%
jean tourrilhesjean tourrilhes27.69%150.00%
Total26100.00%2100.00%

/* * Function irlap_connect_request (self, daddr, qos_user, sniff) * * Request connection with another device, sniffing is not implemented * yet. * */
void irlap_connect_request(struct irlap_cb *self, __u32 daddr, struct qos_info *qos_user, int sniff) { pr_debug("%s(), daddr=0x%08x\n", __func__, daddr); IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); self->daddr = daddr; /* * If the service user specifies QoS values for this connection, * then use them */ irlap_init_qos_capabilities(self, qos_user); if ((self->state == LAP_NDM) && !self->media_busy) irlap_do_event(self, CONNECT_REQUEST, NULL, NULL); else self->connect_pending = TRUE; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8492.31%444.44%
jean tourrilhesjean tourrilhes44.40%222.22%
joe perchesjoe perches11.10%111.11%
martin daleckimartin dalecki11.10%111.11%
harvey harrisonharvey harrison11.10%111.11%
Total91100.00%9100.00%

/* * Function irlap_connect_confirm (self, skb) * * Connection request has been accepted * */
void irlap_connect_confirm(struct irlap_cb *self, struct sk_buff *skb) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); irlmp_link_connect_confirm(self->notify.instance, &self->qos_tx, skb); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4395.56%150.00%
jean tourrilhesjean tourrilhes24.44%150.00%
Total45100.00%2100.00%

/* * Function irlap_data_indication (self, skb) * * Received data frames from IR-port, so we just pass them up to * IrLMP for further processing * */
void irlap_data_indication(struct irlap_cb *self, struct sk_buff *skb, int unreliable) { /* Hide LAP header from IrLMP layer */ skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER); irlmp_link_data_indication(self->notify.instance, skb, unreliable); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git41100.00%2100.00%
Total41100.00%2100.00%

/* * Function irlap_data_request (self, skb) * * Queue data for transmission, must wait until XMIT state * */
void irlap_data_request(struct irlap_cb *self, struct sk_buff *skb, int unreliable) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER), return;); skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER); /* * Must set frame format now so that the rest of the code knows * if its dealing with an I or an UI frame */ if (unreliable) skb->data[1] = UI_FRAME; else skb->data[1] = I_FRAME; /* Don't forget to refcount it - see irlmp_connect_request(). */ skb_get(skb); /* Add at the end of the queue (keep ordering) - Jean II */ skb_queue_tail(&self->txq, skb); /* * Send event if this frame only if we are in the right state * FIXME: udata should be sent first! (skb_queue_head?) */ if ((self->state == LAP_XMIT_P) || (self->state == LAP_XMIT_S)) { /* If we are not already processing the Tx queue, trigger * transmission immediately - Jean II */ if((skb_queue_len(&self->txq) <= 1) && (!self->local_busy)) irlap_do_event(self, DATA_REQUEST, skb, NULL); /* Otherwise, the packets will be sent normally at the * next pf-poll - Jean II */ } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git10875.00%342.86%
jean tourrilhesjean tourrilhes3423.61%342.86%
martin daleckimartin dalecki21.39%114.29%
Total144100.00%7100.00%

/* * Function irlap_unitdata_request (self, skb) * * Send Ultra data. This is data that must be sent outside any connection * */ #ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_request(struct irlap_cb *self, struct sk_buff *skb) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(skb_headroom(skb) >= (LAP_ADDR_HEADER+LAP_CTRL_HEADER), return;); skb_push(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER); skb->data[0] = CBROADCAST; skb->data[1] = UI_FRAME; /* Don't need to refcount, see irlmp_connless_data_request() */ skb_queue_tail(&self->txq_ultra, skb); irlap_do_event(self, SEND_UI_FRAME, NULL, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8195.29%466.67%
jean tourrilhesjean tourrilhes44.71%233.33%
Total85100.00%6100.00%

#endif /*CONFIG_IRDA_ULTRA */ /* * Function irlap_udata_indication (self, skb) * * Receive Ultra data. This is data that is received outside any connection * */ #ifdef CONFIG_IRDA_ULTRA
void irlap_unitdata_indication(struct irlap_cb *self, struct sk_buff *skb) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(skb != NULL, return;); /* Hide LAP header from IrLMP layer */ skb_pull(skb, LAP_ADDR_HEADER+LAP_CTRL_HEADER); irlmp_link_unitdata_indication(self->notify.instance, skb); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5494.74%150.00%
jean tourrilhesjean tourrilhes35.26%150.00%
Total57100.00%2100.00%

#endif /* CONFIG_IRDA_ULTRA */ /* * Function irlap_disconnect_request (void) * * Request to disconnect connection by service user */
void irlap_disconnect_request(struct irlap_cb *self) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* Don't disconnect until all data frames are successfully sent */ if (!skb_queue_empty(&self->txq)) { self->disconnect_pending = TRUE; return; } /* Check if we are in the right state for disconnecting */ switch (self->state) { case LAP_XMIT_P: /* FALLTHROUGH */ case LAP_XMIT_S: /* FALLTHROUGH */ case LAP_CONN: /* FALLTHROUGH */ case LAP_RESET_WAIT: /* FALLTHROUGH */ case LAP_RESET_CHECK: irlap_do_event(self, DISCONNECT_REQUEST, NULL, NULL); break; default: pr_debug("%s(), disconnect pending!\n", __func__); self->disconnect_pending = TRUE; break; } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git8888.00%333.33%
jean tourrilhesjean tourrilhes44.00%222.22%
andre goddard rosaandre goddard rosa44.00%111.11%
david s. millerdavid s. miller22.00%111.11%
harvey harrisonharvey harrison11.00%111.11%
joe perchesjoe perches11.00%111.11%
Total100100.00%9100.00%

/* * Function irlap_disconnect_indication (void) * * Disconnect request from other device * */
void irlap_disconnect_indication(struct irlap_cb *self, LAP_REASON reason) { pr_debug("%s(), reason=%s\n", __func__, lap_reasons[reason]); IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* Flush queues */ irlap_flush_all_queues(self); switch (reason) { case LAP_RESET_INDICATION: pr_debug("%s(), Sending reset request!\n", __func__); irlap_do_event(self, RESET_REQUEST, NULL, NULL); break; case LAP_NO_RESPONSE: /* FALLTHROUGH */ case LAP_DISC_INDICATION: /* FALLTHROUGH */ case LAP_FOUND_NONE: /* FALLTHROUGH */ case LAP_MEDIA_BUSY: irlmp_link_disconnect_indication(self->notify.instance, self, reason, NULL); break; default: net_err_ratelimited("%s: Unknown reason %d\n", __func__, reason); } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git9785.09%222.22%
jean tourrilhesjean tourrilhes65.26%222.22%
harvey harrisonharvey harrison32.63%111.11%
joe perchesjoe perches32.63%222.22%
andre goddard rosaandre goddard rosa32.63%111.11%
martin daleckimartin dalecki21.75%111.11%
Total114100.00%9100.00%

/* * Function irlap_discovery_request (gen_addr_bit) * * Start one single discovery operation. * */
void irlap_discovery_request(struct irlap_cb *self, discovery_t *discovery) { struct irlap_info info; IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(discovery != NULL, return;); pr_debug("%s(), nslots = %d\n", __func__, discovery->nslots); IRDA_ASSERT((discovery->nslots == 1) || (discovery->nslots == 6) || (discovery->nslots == 8) || (discovery->nslots == 16), return;); /* Discovery is only possible in NDM mode */ if (self->state != LAP_NDM) { pr_debug("%s(), discovery only possible in NDM mode\n", __func__); irlap_discovery_confirm(self, NULL); /* Note : in theory, if we are not in NDM, we could postpone * the discovery like we do for connection request. * In practice, it's not worth it. If the media was busy, * it's likely next time around it won't be busy. If we are * in REPLY state, we will get passive discovery info & event. * Jean II */ return; } /* Check if last discovery request finished in time, or if * it was aborted due to the media busy flag. */ if (self->discovery_log != NULL) { hashbin_delete(self->discovery_log, (FREE_FUNC) kfree); self->discovery_log = NULL; } /* All operations will occur at predictable time, no need to lock */ self->discovery_log = hashbin_new(HB_NOLOCK); if (self->discovery_log == NULL) { net_warn_ratelimited("%s(), Unable to allocate discovery log!\n", __func__); return; } info.S = discovery->nslots; /* Number of slots */ info.s = 0; /* Current slot */ self->discovery_cmd = discovery; info.discovery = discovery; /* sysctl_slot_timeout bounds are checked in irsysctl.c - Jean II */ self->slot_timeout = msecs_to_jiffies(sysctl_slot_timeout); irlap_do_event(self, DISCOVERY_REQUEST, NULL, &info); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git16080.40%637.50%
jean tourrilhesjean tourrilhes2713.57%425.00%
linus torvaldslinus torvalds31.51%212.50%
harvey harrisonharvey harrison31.51%16.25%
nicholas mc guirenicholas mc guire31.51%16.25%
joe perchesjoe perches31.51%212.50%
Total199100.00%16100.00%

/* * Function irlap_discovery_confirm (log) * * A device has been discovered in front of this station, we * report directly to LMP. */
void irlap_discovery_confirm(struct irlap_cb *self, hashbin_t *discovery_log) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(self->notify.instance != NULL, return;); /* * Check for successful discovery, since we are then allowed to clear * the media busy condition (IrLAP 6.13.4 - p.94). This should allow * us to make connection attempts much faster and easier (i.e. no * collisions). * Setting media busy to false will also generate an event allowing * to process pending events in NDM state machine. * Note : the spec doesn't define what's a successful discovery is. * If we want Ultra to work, it's successful even if there is * nobody discovered - Jean II */ if (discovery_log) irda_device_set_media_busy(self->netdev, FALSE); /* Inform IrLMP */ irlmp_link_discovery_confirm(self->notify.instance, discovery_log); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5793.44%360.00%
jean tourrilhesjean tourrilhes34.92%120.00%
martin daleckimartin dalecki11.64%120.00%
Total61100.00%5100.00%

/* * Function irlap_discovery_indication (log) * * Somebody is trying to discover us! * */
void irlap_discovery_indication(struct irlap_cb *self, discovery_t *discovery) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(discovery != NULL, return;); IRDA_ASSERT(self->notify.instance != NULL, return;); /* A device is very likely to connect immediately after it performs * a successful discovery. This means that in our case, we are much * more likely to receive a connection request over the medium. * So, we backoff to avoid collisions. * IrLAP spec 6.13.4 suggest 100ms... * Note : this little trick actually make a *BIG* difference. If I set * my Linux box with discovery enabled and one Ultra frame sent every * second, my Palm has no trouble connecting to it every time ! * Jean II */ irda_device_set_media_busy(self->netdev, SMALL); irlmp_link_discovery_indication(self->notify.instance, discovery); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git4977.78%250.00%
linus torvaldslinus torvalds1015.87%125.00%
jean tourrilhesjean tourrilhes46.35%125.00%
Total63100.00%4100.00%

/* * Function irlap_status_indication (quality_of_link) */
void irlap_status_indication(struct irlap_cb *self, int quality_of_link) { switch (quality_of_link) { case STATUS_NO_ACTIVITY: net_info_ratelimited("IrLAP, no activity on link!\n"); break; case STATUS_NOISY: net_info_ratelimited("IrLAP, noisy link!\n"); break; default: break; } irlmp_status_indication(self->notify.instance, quality_of_link, LOCK_NO_CHANGE); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5096.15%375.00%
joe perchesjoe perches23.85%125.00%
Total52100.00%4100.00%

/* * Function irlap_reset_indication (void) */
void irlap_reset_indication(struct irlap_cb *self) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); if (self->state == LAP_RESET_WAIT) irlap_do_event(self, RESET_REQUEST, NULL, NULL); else irlap_do_event(self, RESET_RESPONSE, NULL, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5396.36%266.67%
jean tourrilhesjean tourrilhes23.64%133.33%
Total55100.00%3100.00%

/* * Function irlap_reset_confirm (void) */
void irlap_reset_confirm(void) { }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git583.33%150.00%
joe perchesjoe perches116.67%150.00%
Total6100.00%2100.00%

/* * Function irlap_generate_rand_time_slot (S, s) * * Generate a random time slot between s and S-1 where * S = Number of slots (0 -> S-1) * s = Current slot */
int irlap_generate_rand_time_slot(int S, int s) { static int rand; int slot; IRDA_ASSERT((S - s) > 0, return 0;); rand += jiffies; rand ^= (rand << 12); rand ^= (rand >> 20); slot = s + rand % (S-s); IRDA_ASSERT((slot >= s) || (slot < S), return 0;); return slot; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git7097.22%375.00%
jean tourrilhesjean tourrilhes22.78%125.00%
Total72100.00%4100.00%

/* * Function irlap_update_nr_received (nr) * * Remove all acknowledged frames in current window queue. This code is * not intuitive and you should not try to change it. If you think it * contains bugs, please mail a patch to the author instead. */
void irlap_update_nr_received(struct irlap_cb *self, int nr) { struct sk_buff *skb = NULL; int count = 0; /* * Remove all the ack-ed frames from the window queue. */ /* * Optimize for the common case. It is most likely that the receiver * will acknowledge all the frames we have sent! So in that case we * delete all frames stored in window. */ if (nr == self->vs) { while ((skb = skb_dequeue(&self->wx_list)) != NULL) { dev_kfree_skb(skb); } /* The last acked frame is the next to send minus one */ self->va = nr - 1; } else { /* Remove all acknowledged frames in current window */ while ((skb_peek(&self->wx_list) != NULL) && (((self->va+1) % 8) != nr)) { skb = skb_dequeue(&self->wx_list); dev_kfree_skb(skb); self->va = (self->va + 1) % 8; count++; } } /* Advance window */ self->window = self->window_size - skb_queue_len(&self->wx_list); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git15298.70%133.33%
martin daleckimartin dalecki10.65%133.33%
hideaki yoshifujihideaki yoshifuji10.65%133.33%
Total154100.00%3100.00%

/* * Function irlap_validate_ns_received (ns) * * Validate the next to send (ns) field from received frame. */
int irlap_validate_ns_received(struct irlap_cb *self, int ns) { /* ns as expected? */ if (ns == self->vr) return NS_EXPECTED; /* * Stations are allowed to treat invalid NS as unexpected NS * IrLAP, Recv ... with-invalid-Ns. p. 84 */ return NS_UNEXPECTED; /* return NR_INVALID; */ }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git30100.00%2100.00%
Total30100.00%2100.00%

/* * Function irlap_validate_nr_received (nr) * * Validate the next to receive (nr) field from received frame. * */
int irlap_validate_nr_received(struct irlap_cb *self, int nr) { /* nr as expected? */ if (nr == self->vs) { pr_debug("%s(), expected!\n", __func__); return NR_EXPECTED; } /* * unexpected nr? (but within current window), first we check if the * ns numbers of the frames in the current window wrap. */ if (self->va < self->vs) { if ((nr >= self->va) && (nr <= self->vs)) return NR_UNEXPECTED; } else { if ((nr >= self->va) || (nr <= self->vs)) return NR_UNEXPECTED; } /* Invalid nr! */ return NR_INVALID; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git9194.79%233.33%
jean tourrilhesjean tourrilhes22.08%116.67%
harvey harrisonharvey harrison11.04%116.67%
joe perchesjoe perches11.04%116.67%
martin daleckimartin dalecki11.04%116.67%
Total96100.00%6100.00%

/* * Function irlap_initiate_connection_state () * * Initialize the connection state parameters * */
void irlap_initiate_connection_state(struct irlap_cb *self) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* Next to send and next to receive */ self->vs = self->vr = 0; /* Last frame which got acked (0 - 1) % 8 */ self->va = 7; self->window = 1; self->remote_busy = FALSE; self->retry_count = 0; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git5896.67%266.67%
jean tourrilhesjean tourrilhes23.33%133.33%
Total60100.00%3100.00%

/* * Function irlap_wait_min_turn_around (self, qos) * * Wait negotiated minimum turn around time, this function actually sets * the number of BOS's that must be sent before the next transmitted * frame in order to delay for the specified amount of time. This is * done to avoid using timers, and the forbidden udelay! */
void irlap_wait_min_turn_around(struct irlap_cb *self, struct qos_info *qos) { __u32 min_turn_time; __u32 speed; /* Get QoS values. */ speed = qos->baud_rate.value; min_turn_time = qos->min_turn_time.value; /* No need to calculate XBOFs for speeds over 115200 bps */ if (speed > 115200) { self->mtt_required = min_turn_time; return; } /* * Send additional BOF's for the next frame for the requested * min turn time, so now we must calculate how many chars (XBOF's) we * must send for the requested time period (min turn time) */ self->xbofs_delay = irlap_min_turn_time_in_bytes(speed, min_turn_time); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git6598.48%480.00%
martin daleckimartin dalecki11.52%120.00%
Total66100.00%5100.00%

/* * Function irlap_flush_all_queues (void) * * Flush all queues * */
void irlap_flush_all_queues(struct irlap_cb *self) { struct sk_buff* skb; IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* Free transmission queue */ while ((skb = skb_dequeue(&self->txq)) != NULL) dev_kfree_skb(skb); while ((skb = skb_dequeue(&self->txq_ultra)) != NULL) dev_kfree_skb(skb); /* Free sliding window buffered packets */ while ((skb = skb_dequeue(&self->wx_list)) != NULL) dev_kfree_skb(skb); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git9297.87%375.00%
jean tourrilhesjean tourrilhes22.13%125.00%
Total94100.00%4100.00%

/* * Function irlap_setspeed (self, speed) * * Change the speed of the IrDA port * */
static void irlap_change_speed(struct irlap_cb *self, __u32 speed, int now) { struct sk_buff *skb; pr_debug("%s(), setting speed to %d\n", __func__, speed); IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); self->speed = speed; /* Change speed now, or just piggyback speed on frames */ if (now) { /* Send down empty frame to trigger speed change */ skb = alloc_skb(0, GFP_ATOMIC); if (skb) irlap_queue_xmit(self, skb); } }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git6582.28%436.36%
florin malitaflorin malita45.06%19.09%
jean tourrilhesjean tourrilhes45.06%218.18%
samuel ortizsamuel ortiz33.80%19.09%
joe perchesjoe perches11.27%19.09%
adrian bunkadrian bunk11.27%19.09%
harvey harrisonharvey harrison11.27%19.09%
Total79100.00%11100.00%

/* * Function irlap_init_qos_capabilities (self, qos) * * Initialize QoS for this IrLAP session, What we do is to compute the * intersection of the QoS capabilities for the user, driver and for * IrLAP itself. Normally, IrLAP will not specify any values, but it can * be used to restrict certain values. */
static void irlap_init_qos_capabilities(struct irlap_cb *self, struct qos_info *qos_user) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); IRDA_ASSERT(self->netdev != NULL, return;); /* Start out with the maximum QoS support possible */ irda_init_max_qos_capabilies(&self->qos_rx); /* Apply drivers QoS capabilities */ irda_qos_compute_intersection(&self->qos_rx, self->qos_dev); /* * Check for user supplied QoS parameters. The service user is only * allowed to supply these values. We check each parameter since the * user may not have set all of them. */ if (qos_user) { pr_debug("%s(), Found user specified QoS!\n", __func__); if (qos_user->baud_rate.bits) self->qos_rx.baud_rate.bits &= qos_user->baud_rate.bits; if (qos_user->max_turn_time.bits) self->qos_rx.max_turn_time.bits &= qos_user->max_turn_time.bits; if (qos_user->data_size.bits) self->qos_rx.data_size.bits &= qos_user->data_size.bits; if (qos_user->link_disc_time.bits) self->qos_rx.link_disc_time.bits &= qos_user->link_disc_time.bits; } /* Use 500ms in IrLAP for now */ self->qos_rx.max_turn_time.bits &= 0x01; /* Set data size */ /*self->qos_rx.data_size.bits &= 0x03;*/ irda_qos_bits_to_value(&self->qos_rx); }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git17395.05%545.45%
jean tourrilhesjean tourrilhes52.75%218.18%
harvey harrisonharvey harrison10.55%19.09%
joe perchesjoe perches10.55%19.09%
adrian bunkadrian bunk10.55%19.09%
martin daleckimartin dalecki10.55%19.09%
Total182100.00%11100.00%

/* * Function irlap_apply_default_connection_parameters (void, now) * * Use the default connection and transmission parameters */
void irlap_apply_default_connection_parameters(struct irlap_cb *self) { IRDA_ASSERT(self != NULL, return;); IRDA_ASSERT(self->magic == LAP_MAGIC, return;); /* xbofs : Default value in NDM */ self->next_bofs = 12; self->bofs_count = 12; /* NDM Speed is 9600 */ irlap_change_speed(self, 9600, TRUE); /* Set mbusy when going to NDM state */ irda_device_set_media_busy(self->netdev, TRUE); /* * Generate random connection address for this session, which must * be 7 bits wide and different from 0x00 and 0xfe */ while ((self->caddr == 0x00) || (self->caddr == 0xfe)) { get_random_bytes(&self->caddr, sizeof(self->caddr)); self->caddr &= 0xfe; } /* Use default values until connection has been negitiated */ self->slot_timeout = sysctl_slot_timeout; self->final_timeout = FINAL_TIMEOUT; self->poll_timeout = POLL_TIMEOUT; self->wd_timeout = WD_TIMEOUT; /* Set some default values */ self->qos_tx.baud_rate.value = 9600; self->qos_rx.baud_rate.value = 9600; self->qos_tx.max_turn_time.value = 0; self->qos_rx.max_turn_time.value = 0; self->qos_tx.min_turn_time.value = 0; self->qos_rx.min_turn_time.value = 0; self->qos_tx.data_size.value = 64; self->qos_rx.data_size.value = 64; self->qos_tx.window_size.value = 1; self->qos_rx.window_size.value = 1; self->qos_tx.additional_bofs.value = 12; self->qos_rx.additional_bofs.value = 12; self->qos_tx.link_disc_time.value = 0; self->qos_rx.link_disc_time.value = 0; irlap_flush_all_queues(self); self->disconnect_pending = FALSE; self->connect_pending = FALSE; }

Contributors

PersonTokensPropCommitsCommitProp
pre-gitpre-git26593.97%562.50%
linus torvaldslinus torvalds144.96%112.50%
jean tourrilhesjean tourrilhes20.71%112.50%
martin daleckimartin dalecki10.35%112.50%
Total282100.00%8100.00%

/* * Function irlap_apply_connection_parameters (qos, now) * * Initialize IrLAP with the negotiated QoS values * * If 'now' is false, the speed and xbofs will be changed after the next * frame is sent. * If 'now' is true, the speed and xbofs is changed immediately */
void irlap_apply_connection_parameters(struct irlap_cb *