ng_l2cap_misc.c (137163) | ng_l2cap_misc.c (138268) |
---|---|
1/* 2 * ng_l2cap_misc.c 3 * 4 * Copyright (c) Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: ng_l2cap_misc.c,v 1.5 2003/09/08 19:11:45 max Exp $ | 1/* 2 * ng_l2cap_misc.c 3 * 4 * Copyright (c) Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 12 unchanged lines hidden (view full) --- 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: ng_l2cap_misc.c,v 1.5 2003/09/08 19:11:45 max Exp $ |
29 * $FreeBSD: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c 137163 2004-11-03 18:00:49Z emax $ | 29 * $FreeBSD: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_misc.c 138268 2004-12-01 11:56:32Z glebius $ |
30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/mbuf.h> 37#include <sys/queue.h> --- 148 unchanged lines hidden (view full) --- 186 (con->state == NG_L2CAP_CON_OPEN) && 187 (con->flags & NG_L2CAP_CON_OUTGOING) && 188 (con->l2cap->discon_timo > 0)) 189 ng_l2cap_discon_timeout(con); 190} /* ng_l2cap_con_unref */ 191 192/* 193 * Set auto disconnect timeout | 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/malloc.h> 36#include <sys/mbuf.h> 37#include <sys/queue.h> --- 148 unchanged lines hidden (view full) --- 186 (con->state == NG_L2CAP_CON_OPEN) && 187 (con->flags & NG_L2CAP_CON_OUTGOING) && 188 (con->l2cap->discon_timo > 0)) 189 ng_l2cap_discon_timeout(con); 190} /* ng_l2cap_con_unref */ 191 192/* 193 * Set auto disconnect timeout |
194 * XXX FIXME: check return code from ng_timeout | 194 * XXX FIXME: check return code from ng_callout |
195 */ 196 197int 198ng_l2cap_discon_timeout(ng_l2cap_con_p con) 199{ 200 if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO)) 201 panic( 202"%s: %s - invalid timeout, state=%d, flags=%#x\n", 203 __func__, NG_NODE_NAME(con->l2cap->node), 204 con->state, con->flags); 205 206 con->flags |= NG_L2CAP_CON_AUTO_DISCON_TIMO; | 195 */ 196 197int 198ng_l2cap_discon_timeout(ng_l2cap_con_p con) 199{ 200 if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO)) 201 panic( 202"%s: %s - invalid timeout, state=%d, flags=%#x\n", 203 __func__, NG_NODE_NAME(con->l2cap->node), 204 con->state, con->flags); 205 206 con->flags |= NG_L2CAP_CON_AUTO_DISCON_TIMO; |
207 ng_timeout(&con->con_timo, con->l2cap->node, NULL, | 207 ng_callout(&con->con_timo, con->l2cap->node, NULL, |
208 con->l2cap->discon_timo * hz, 209 ng_l2cap_process_discon_timeout, NULL, 210 con->con_handle); 211 212 return (0); 213} /* ng_l2cap_discon_timeout */ 214 215/* --- 4 unchanged lines hidden (view full) --- 220ng_l2cap_discon_untimeout(ng_l2cap_con_p con) 221{ 222 if (!(con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)) 223 panic( 224"%s: %s - no disconnect timeout, state=%d, flags=%#x\n", 225 __func__, NG_NODE_NAME(con->l2cap->node), 226 con->state, con->flags); 227 | 208 con->l2cap->discon_timo * hz, 209 ng_l2cap_process_discon_timeout, NULL, 210 con->con_handle); 211 212 return (0); 213} /* ng_l2cap_discon_timeout */ 214 215/* --- 4 unchanged lines hidden (view full) --- 220ng_l2cap_discon_untimeout(ng_l2cap_con_p con) 221{ 222 if (!(con->flags & NG_L2CAP_CON_AUTO_DISCON_TIMO)) 223 panic( 224"%s: %s - no disconnect timeout, state=%d, flags=%#x\n", 225 __func__, NG_NODE_NAME(con->l2cap->node), 226 con->state, con->flags); 227 |
228 if (ng_untimeout(&con->con_timo, con->l2cap->node) == 0) | 228 if (ng_uncallout(&con->con_timo, con->l2cap->node) == 0) |
229 return (ETIMEDOUT); 230 231 con->flags &= ~NG_L2CAP_CON_AUTO_DISCON_TIMO; 232 233 return (0); 234} /* ng_l2cap_discon_untimeout */ 235 236/* --- 211 unchanged lines hidden (view full) --- 448 } 449 } 450 451 return (cmd); 452} /* ng_l2cap_cmd_by_ident */ 453 454/* 455 * Set LP timeout | 229 return (ETIMEDOUT); 230 231 con->flags &= ~NG_L2CAP_CON_AUTO_DISCON_TIMO; 232 233 return (0); 234} /* ng_l2cap_discon_untimeout */ 235 236/* --- 211 unchanged lines hidden (view full) --- 448 } 449 } 450 451 return (cmd); 452} /* ng_l2cap_cmd_by_ident */ 453 454/* 455 * Set LP timeout |
456 * XXX FIXME: check return code from ng_timeout | 456 * XXX FIXME: check return code from ng_callout |
457 */ 458 459int 460ng_l2cap_lp_timeout(ng_l2cap_con_p con) 461{ 462 if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO)) 463 panic( 464"%s: %s - invalid timeout, state=%d, flags=%#x\n", 465 __func__, NG_NODE_NAME(con->l2cap->node), 466 con->state, con->flags); 467 468 con->flags |= NG_L2CAP_CON_LP_TIMO; | 457 */ 458 459int 460ng_l2cap_lp_timeout(ng_l2cap_con_p con) 461{ 462 if (con->flags & (NG_L2CAP_CON_LP_TIMO|NG_L2CAP_CON_AUTO_DISCON_TIMO)) 463 panic( 464"%s: %s - invalid timeout, state=%d, flags=%#x\n", 465 __func__, NG_NODE_NAME(con->l2cap->node), 466 con->state, con->flags); 467 468 con->flags |= NG_L2CAP_CON_LP_TIMO; |
469 ng_timeout(&con->con_timo, con->l2cap->node, NULL, | 469 ng_callout(&con->con_timo, con->l2cap->node, NULL, |
470 bluetooth_hci_connect_timeout(), 471 ng_l2cap_process_lp_timeout, NULL, 472 con->con_handle); 473 474 return (0); 475} /* ng_l2cap_lp_timeout */ 476 477/* --- 4 unchanged lines hidden (view full) --- 482ng_l2cap_lp_untimeout(ng_l2cap_con_p con) 483{ 484 if (!(con->flags & NG_L2CAP_CON_LP_TIMO)) 485 panic( 486"%s: %s - no LP connection timeout, state=%d, flags=%#x\n", 487 __func__, NG_NODE_NAME(con->l2cap->node), 488 con->state, con->flags); 489 | 470 bluetooth_hci_connect_timeout(), 471 ng_l2cap_process_lp_timeout, NULL, 472 con->con_handle); 473 474 return (0); 475} /* ng_l2cap_lp_timeout */ 476 477/* --- 4 unchanged lines hidden (view full) --- 482ng_l2cap_lp_untimeout(ng_l2cap_con_p con) 483{ 484 if (!(con->flags & NG_L2CAP_CON_LP_TIMO)) 485 panic( 486"%s: %s - no LP connection timeout, state=%d, flags=%#x\n", 487 __func__, NG_NODE_NAME(con->l2cap->node), 488 con->state, con->flags); 489 |
490 if (ng_untimeout(&con->con_timo, con->l2cap->node) == 0) | 490 if (ng_uncallout(&con->con_timo, con->l2cap->node) == 0) |
491 return (ETIMEDOUT); 492 493 con->flags &= ~NG_L2CAP_CON_LP_TIMO; 494 495 return (0); 496} /* ng_l2cap_lp_untimeout */ 497 498/* 499 * Set L2CAP command timeout | 491 return (ETIMEDOUT); 492 493 con->flags &= ~NG_L2CAP_CON_LP_TIMO; 494 495 return (0); 496} /* ng_l2cap_lp_untimeout */ 497 498/* 499 * Set L2CAP command timeout |
500 * XXX FIXME: check return code from ng_timeout | 500 * XXX FIXME: check return code from ng_callout |
501 */ 502 503int 504ng_l2cap_command_timeout(ng_l2cap_cmd_p cmd, int timo) 505{ 506 int arg; 507 508 if (cmd->flags & NG_L2CAP_CMD_PENDING) 509 panic( 510"%s: %s - duplicated command timeout, code=%#x, flags=%#x\n", 511 __func__, NG_NODE_NAME(cmd->con->l2cap->node), 512 cmd->code, cmd->flags); 513 514 arg = ((cmd->ident << 16) | cmd->con->con_handle); 515 cmd->flags |= NG_L2CAP_CMD_PENDING; | 501 */ 502 503int 504ng_l2cap_command_timeout(ng_l2cap_cmd_p cmd, int timo) 505{ 506 int arg; 507 508 if (cmd->flags & NG_L2CAP_CMD_PENDING) 509 panic( 510"%s: %s - duplicated command timeout, code=%#x, flags=%#x\n", 511 __func__, NG_NODE_NAME(cmd->con->l2cap->node), 512 cmd->code, cmd->flags); 513 514 arg = ((cmd->ident << 16) | cmd->con->con_handle); 515 cmd->flags |= NG_L2CAP_CMD_PENDING; |
516 ng_timeout(&cmd->timo, cmd->con->l2cap->node, NULL, timo, | 516 ng_callout(&cmd->timo, cmd->con->l2cap->node, NULL, timo, |
517 ng_l2cap_process_command_timeout, NULL, arg); 518 519 return (0); 520} /* ng_l2cap_command_timeout */ 521 522/* 523 * Unset L2CAP command timeout 524 */ 525 526int 527ng_l2cap_command_untimeout(ng_l2cap_cmd_p cmd) 528{ 529 if (!(cmd->flags & NG_L2CAP_CMD_PENDING)) 530 panic( 531"%s: %s - no command timeout, code=%#x, flags=%#x\n", 532 __func__, NG_NODE_NAME(cmd->con->l2cap->node), 533 cmd->code, cmd->flags); 534 | 517 ng_l2cap_process_command_timeout, NULL, arg); 518 519 return (0); 520} /* ng_l2cap_command_timeout */ 521 522/* 523 * Unset L2CAP command timeout 524 */ 525 526int 527ng_l2cap_command_untimeout(ng_l2cap_cmd_p cmd) 528{ 529 if (!(cmd->flags & NG_L2CAP_CMD_PENDING)) 530 panic( 531"%s: %s - no command timeout, code=%#x, flags=%#x\n", 532 __func__, NG_NODE_NAME(cmd->con->l2cap->node), 533 cmd->code, cmd->flags); 534 |
535 if (ng_untimeout(&cmd->timo, cmd->con->l2cap->node) == 0) | 535 if (ng_uncallout(&cmd->timo, cmd->con->l2cap->node) == 0) |
536 return (ETIMEDOUT); 537 538 cmd->flags &= ~NG_L2CAP_CMD_PENDING; 539 540 return (0); 541} /* ng_l2cap_command_untimeout */ 542 543/* --- 89 unchanged lines hidden --- | 536 return (ETIMEDOUT); 537 538 cmd->flags &= ~NG_L2CAP_CMD_PENDING; 539 540 return (0); 541} /* ng_l2cap_command_untimeout */ 542 543/* --- 89 unchanged lines hidden --- |