Lines Matching +full:ctrl +full:- +full:len
3 Copyright (C) 2002-2003 Marcel Holtmann <marcel@holtmann.org>
82 app->state = BT_OPEN; in cmtp_application_add()
83 app->appl = appl; in cmtp_application_add()
85 list_add_tail(&app->list, &session->applications); in cmtp_application_add()
95 list_del(&app->list); in cmtp_application_del()
104 list_for_each_entry(app, &session->applications, list) { in cmtp_application_get()
107 if (app->msgnum == value) in cmtp_application_get()
111 if (app->appl == value) in cmtp_application_get()
115 if (app->mapping == value) in cmtp_application_get()
126 session->msgnum++; in cmtp_msgnum_get()
128 if ((session->msgnum & 0xff) > 200) in cmtp_msgnum_get()
129 session->msgnum = CMTP_INITIAL_MSGNUM + 1; in cmtp_msgnum_get()
131 return session->msgnum; in cmtp_msgnum_get()
136 struct cmtp_scb *scb = (void *) skb->cb; in cmtp_send_capimsg()
138 BT_DBG("session %p skb %p len %u", session, skb, skb->len); in cmtp_send_capimsg()
140 scb->id = -1; in cmtp_send_capimsg()
141 scb->data = (CAPIMSG_COMMAND(skb->data) == CAPI_DATA_B3); in cmtp_send_capimsg()
143 skb_queue_tail(&session->transmit, skb); in cmtp_send_capimsg()
145 wake_up_interruptible(sk_sleep(session->sock->sk)); in cmtp_send_capimsg()
150 __u16 function, unsigned char *buf, int len) in cmtp_send_interopmsg() argument
157 skb = alloc_skb(CAPI_MSG_BASELEN + 6 + len, GFP_ATOMIC); in cmtp_send_interopmsg()
163 s = skb_put(skb, CAPI_MSG_BASELEN + 6 + len); in cmtp_send_interopmsg()
165 capimsg_setu16(s, 0, CAPI_MSG_BASELEN + 6 + len); in cmtp_send_interopmsg()
174 capimsg_setu8 (s, 10, 3 + len); in cmtp_send_interopmsg()
176 capimsg_setu8 (s, 13, len); in cmtp_send_interopmsg()
178 if (len > 0) in cmtp_send_interopmsg()
179 memcpy(s + 14, buf, len); in cmtp_send_interopmsg()
186 struct capi_ctr *ctrl = &session->ctrl; in cmtp_recv_interopmsg() local
191 BT_DBG("session %p skb %p len %u", session, skb, skb->len); in cmtp_recv_interopmsg()
193 switch (CAPIMSG_SUBCOMMAND(skb->data)) { in cmtp_recv_interopmsg()
195 if (skb->len < CAPI_MSG_BASELEN + 10) in cmtp_recv_interopmsg()
198 func = CAPIMSG_U16(skb->data, CAPI_MSG_BASELEN + 5); in cmtp_recv_interopmsg()
199 info = CAPIMSG_U16(skb->data, CAPI_MSG_BASELEN + 8); in cmtp_recv_interopmsg()
203 msgnum = CAPIMSG_MSGID(skb->data); in cmtp_recv_interopmsg()
207 application->state = BT_CONNECTED; in cmtp_recv_interopmsg()
208 application->msgnum = 0; in cmtp_recv_interopmsg()
209 application->mapping = CAPIMSG_APPID(skb->data); in cmtp_recv_interopmsg()
210 wake_up_interruptible(&session->wait); in cmtp_recv_interopmsg()
216 appl = CAPIMSG_APPID(skb->data); in cmtp_recv_interopmsg()
220 application->state = BT_CLOSED; in cmtp_recv_interopmsg()
221 application->msgnum = 0; in cmtp_recv_interopmsg()
222 wake_up_interruptible(&session->wait); in cmtp_recv_interopmsg()
228 if (skb->len < CAPI_MSG_BASELEN + 11 + sizeof(capi_profile)) in cmtp_recv_interopmsg()
231 controller = CAPIMSG_U16(skb->data, CAPI_MSG_BASELEN + 11); in cmtp_recv_interopmsg()
232 msgnum = CAPIMSG_MSGID(skb->data); in cmtp_recv_interopmsg()
235 session->ncontroller = controller; in cmtp_recv_interopmsg()
236 wake_up_interruptible(&session->wait); in cmtp_recv_interopmsg()
240 if (!info && ctrl) { in cmtp_recv_interopmsg()
241 memcpy(&ctrl->profile, in cmtp_recv_interopmsg()
242 skb->data + CAPI_MSG_BASELEN + 11, in cmtp_recv_interopmsg()
244 session->state = BT_CONNECTED; in cmtp_recv_interopmsg()
245 capi_ctr_ready(ctrl); in cmtp_recv_interopmsg()
251 if (skb->len < CAPI_MSG_BASELEN + 15) in cmtp_recv_interopmsg()
254 if (!info && ctrl) { in cmtp_recv_interopmsg()
255 int len = min_t(uint, CAPI_MANUFACTURER_LEN, in cmtp_recv_interopmsg() local
256 skb->data[CAPI_MSG_BASELEN + 14]); in cmtp_recv_interopmsg()
258 memset(ctrl->manu, 0, CAPI_MANUFACTURER_LEN); in cmtp_recv_interopmsg()
259 strncpy(ctrl->manu, in cmtp_recv_interopmsg()
260 skb->data + CAPI_MSG_BASELEN + 15, len); in cmtp_recv_interopmsg()
266 if (skb->len < CAPI_MSG_BASELEN + 32) in cmtp_recv_interopmsg()
269 if (!info && ctrl) { in cmtp_recv_interopmsg()
270 ctrl->version.majorversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 16); in cmtp_recv_interopmsg()
271 ctrl->version.minorversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 20); in cmtp_recv_interopmsg()
272 ctrl->version.majormanuversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 24); in cmtp_recv_interopmsg()
273 ctrl->version.minormanuversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 28); in cmtp_recv_interopmsg()
279 if (skb->len < CAPI_MSG_BASELEN + 17) in cmtp_recv_interopmsg()
282 if (!info && ctrl) { in cmtp_recv_interopmsg()
283 int len = min_t(uint, CAPI_SERIAL_LEN, in cmtp_recv_interopmsg() local
284 skb->data[CAPI_MSG_BASELEN + 16]); in cmtp_recv_interopmsg()
286 memset(ctrl->serial, 0, CAPI_SERIAL_LEN); in cmtp_recv_interopmsg()
287 strncpy(ctrl->serial, in cmtp_recv_interopmsg()
288 skb->data + CAPI_MSG_BASELEN + 17, len); in cmtp_recv_interopmsg()
297 if (skb->len < CAPI_MSG_BASELEN + 6) in cmtp_recv_interopmsg()
300 func = CAPIMSG_U16(skb->data, CAPI_MSG_BASELEN + 3); in cmtp_recv_interopmsg()
303 int len = min_t(uint, skb->len - CAPI_MSG_BASELEN - 6, in cmtp_recv_interopmsg() local
304 skb->data[CAPI_MSG_BASELEN + 5]); in cmtp_recv_interopmsg()
305 appl = CAPIMSG_APPID(skb->data); in cmtp_recv_interopmsg()
306 msgnum = CAPIMSG_MSGID(skb->data); in cmtp_recv_interopmsg()
308 skb->data + CAPI_MSG_BASELEN + 6, len); in cmtp_recv_interopmsg()
319 struct capi_ctr *ctrl = &session->ctrl; in cmtp_recv_capimsg() local
324 BT_DBG("session %p skb %p len %u", session, skb, skb->len); in cmtp_recv_capimsg()
326 if (skb->len < CAPI_MSG_BASELEN) in cmtp_recv_capimsg()
329 if (CAPIMSG_COMMAND(skb->data) == CAPI_INTEROPERABILITY) { in cmtp_recv_capimsg()
334 if (session->flags & BIT(CMTP_LOOPBACK)) { in cmtp_recv_capimsg()
339 appl = CAPIMSG_APPID(skb->data); in cmtp_recv_capimsg()
340 contr = CAPIMSG_CONTROL(skb->data); in cmtp_recv_capimsg()
344 appl = application->appl; in cmtp_recv_capimsg()
345 CAPIMSG_SETAPPID(skb->data, appl); in cmtp_recv_capimsg()
353 contr = (contr & 0xffffff80) | session->num; in cmtp_recv_capimsg()
354 CAPIMSG_SETCONTROL(skb->data, contr); in cmtp_recv_capimsg()
357 capi_ctr_handle_message(ctrl, appl, skb); in cmtp_recv_capimsg()
360 static int cmtp_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) in cmtp_load_firmware() argument
362 BT_DBG("ctrl %p data %p", ctrl, data); in cmtp_load_firmware()
367 static void cmtp_reset_ctr(struct capi_ctr *ctrl) in cmtp_reset_ctr() argument
369 struct cmtp_session *session = ctrl->driverdata; in cmtp_reset_ctr()
371 BT_DBG("ctrl %p", ctrl); in cmtp_reset_ctr()
373 capi_ctr_down(ctrl); in cmtp_reset_ctr()
375 atomic_inc(&session->terminate); in cmtp_reset_ctr()
376 wake_up_process(session->task); in cmtp_reset_ctr()
379 static void cmtp_register_appl(struct capi_ctr *ctrl, __u16 appl, capi_register_params *rp) in cmtp_register_appl() argument
382 struct cmtp_session *session = ctrl->driverdata; in cmtp_register_appl()
386 int err = 0, nconn, want = rp->level3cnt; in cmtp_register_appl()
388 BT_DBG("ctrl %p appl %u level3cnt %u datablkcnt %u datablklen %u", in cmtp_register_appl()
389 ctrl, appl, rp->level3cnt, rp->datablkcnt, rp->datablklen); in cmtp_register_appl()
398 nconn = ctrl->profile.nbchannel * -want; in cmtp_register_appl()
403 nconn = ctrl->profile.nbchannel; in cmtp_register_appl()
406 capimsg_setu16(buf, 2, rp->datablkcnt); in cmtp_register_appl()
407 capimsg_setu16(buf, 4, rp->datablklen); in cmtp_register_appl()
409 application->state = BT_CONFIG; in cmtp_register_appl()
410 application->msgnum = cmtp_msgnum_get(session); in cmtp_register_appl()
412 cmtp_send_interopmsg(session, CAPI_REQ, 0x0000, application->msgnum, in cmtp_register_appl()
415 add_wait_queue(&session->wait, &wait); in cmtp_register_appl()
420 err = -EAGAIN; in cmtp_register_appl()
424 if (application->state == BT_CLOSED) { in cmtp_register_appl()
425 err = -application->err; in cmtp_register_appl()
429 if (application->state == BT_CONNECTED) in cmtp_register_appl()
433 err = -EINTR; in cmtp_register_appl()
440 remove_wait_queue(&session->wait, &wait); in cmtp_register_appl()
448 static void cmtp_release_appl(struct capi_ctr *ctrl, __u16 appl) in cmtp_release_appl() argument
450 struct cmtp_session *session = ctrl->driverdata; in cmtp_release_appl()
453 BT_DBG("ctrl %p appl %u", ctrl, appl); in cmtp_release_appl()
461 application->msgnum = cmtp_msgnum_get(session); in cmtp_release_appl()
463 cmtp_send_interopmsg(session, CAPI_REQ, application->mapping, application->msgnum, in cmtp_release_appl()
466 wait_event_interruptible_timeout(session->wait, in cmtp_release_appl()
467 (application->state == BT_CLOSED), CMTP_INTEROP_TIMEOUT); in cmtp_release_appl()
472 static u16 cmtp_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) in cmtp_send_message() argument
474 struct cmtp_session *session = ctrl->driverdata; in cmtp_send_message()
479 BT_DBG("ctrl %p skb %p", ctrl, skb); in cmtp_send_message()
481 appl = CAPIMSG_APPID(skb->data); in cmtp_send_message()
482 contr = CAPIMSG_CONTROL(skb->data); in cmtp_send_message()
485 if ((!application) || (application->state != BT_CONNECTED)) { in cmtp_send_message()
490 CAPIMSG_SETAPPID(skb->data, application->mapping); in cmtp_send_message()
492 if ((contr & 0x7f) == session->num) { in cmtp_send_message()
494 CAPIMSG_SETCONTROL(skb->data, contr); in cmtp_send_message()
502 static char *cmtp_procinfo(struct capi_ctr *ctrl) in cmtp_procinfo() argument
509 struct capi_ctr *ctrl = m->private; in cmtp_proc_show() local
510 struct cmtp_session *session = ctrl->driverdata; in cmtp_proc_show()
513 seq_printf(m, "%s\n\n", cmtp_procinfo(ctrl)); in cmtp_proc_show()
514 seq_printf(m, "addr %s\n", session->name); in cmtp_proc_show()
515 seq_printf(m, "ctrl %d\n", session->num); in cmtp_proc_show()
517 list_for_each_entry(app, &session->applications, list) { in cmtp_proc_show()
518 seq_printf(m, "appl %u -> %u\n", app->appl, app->mapping); in cmtp_proc_show()
536 ret = wait_event_interruptible_timeout(session->wait, in cmtp_attach_device()
537 session->ncontroller, CMTP_INTEROP_TIMEOUT); in cmtp_attach_device()
539 BT_INFO("Found %d CAPI controller(s) on device %s", session->ncontroller, session->name); in cmtp_attach_device()
542 return -ETIMEDOUT; in cmtp_attach_device()
544 if (!session->ncontroller) in cmtp_attach_device()
545 return -ENODEV; in cmtp_attach_device()
547 if (session->ncontroller > 1) in cmtp_attach_device()
550 session->ctrl.owner = THIS_MODULE; in cmtp_attach_device()
551 session->ctrl.driverdata = session; in cmtp_attach_device()
552 strcpy(session->ctrl.name, session->name); in cmtp_attach_device()
554 session->ctrl.driver_name = "cmtp"; in cmtp_attach_device()
555 session->ctrl.load_firmware = cmtp_load_firmware; in cmtp_attach_device()
556 session->ctrl.reset_ctr = cmtp_reset_ctr; in cmtp_attach_device()
557 session->ctrl.register_appl = cmtp_register_appl; in cmtp_attach_device()
558 session->ctrl.release_appl = cmtp_release_appl; in cmtp_attach_device()
559 session->ctrl.send_message = cmtp_send_message; in cmtp_attach_device()
561 session->ctrl.procinfo = cmtp_procinfo; in cmtp_attach_device()
562 session->ctrl.proc_show = cmtp_proc_show; in cmtp_attach_device()
564 if (attach_capi_ctr(&session->ctrl) < 0) { in cmtp_attach_device()
566 return -EBUSY; in cmtp_attach_device()
569 session->num = session->ctrl.cnr; in cmtp_attach_device()
571 BT_DBG("session %p num %d", session, session->num); in cmtp_attach_device()
594 detach_capi_ctr(&session->ctrl); in cmtp_detach_device()