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 (!info && ctrl && skb->len > CAPI_MSG_BASELEN + 14) in cmtp_recv_interopmsg()
252 strscpy_pad(ctrl->manu, in cmtp_recv_interopmsg()
253 skb->data + CAPI_MSG_BASELEN + 15, in cmtp_recv_interopmsg()
254 skb->data[CAPI_MSG_BASELEN + 14]); in cmtp_recv_interopmsg()
258 if (skb->len < CAPI_MSG_BASELEN + 32) in cmtp_recv_interopmsg()
261 if (!info && ctrl) { in cmtp_recv_interopmsg()
262 ctrl->version.majorversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 16); in cmtp_recv_interopmsg()
263 ctrl->version.minorversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 20); in cmtp_recv_interopmsg()
264 ctrl->version.majormanuversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 24); in cmtp_recv_interopmsg()
265 ctrl->version.minormanuversion = CAPIMSG_U32(skb->data, CAPI_MSG_BASELEN + 28); in cmtp_recv_interopmsg()
271 if (!info && ctrl && skb->len > CAPI_MSG_BASELEN + 16) in cmtp_recv_interopmsg()
272 strscpy_pad(ctrl->serial, in cmtp_recv_interopmsg()
273 skb->data + CAPI_MSG_BASELEN + 17, in cmtp_recv_interopmsg()
274 skb->data[CAPI_MSG_BASELEN + 16]); in cmtp_recv_interopmsg()
281 if (skb->len < CAPI_MSG_BASELEN + 6) in cmtp_recv_interopmsg()
284 func = CAPIMSG_U16(skb->data, CAPI_MSG_BASELEN + 3); in cmtp_recv_interopmsg()
287 int len = min_t(uint, skb->len - CAPI_MSG_BASELEN - 6, in cmtp_recv_interopmsg() local
288 skb->data[CAPI_MSG_BASELEN + 5]); in cmtp_recv_interopmsg()
289 appl = CAPIMSG_APPID(skb->data); in cmtp_recv_interopmsg()
290 msgnum = CAPIMSG_MSGID(skb->data); in cmtp_recv_interopmsg()
292 skb->data + CAPI_MSG_BASELEN + 6, len); in cmtp_recv_interopmsg()
303 struct capi_ctr *ctrl = &session->ctrl; in cmtp_recv_capimsg() local
308 BT_DBG("session %p skb %p len %u", session, skb, skb->len); in cmtp_recv_capimsg()
310 if (skb->len < CAPI_MSG_BASELEN) in cmtp_recv_capimsg()
313 if (CAPIMSG_COMMAND(skb->data) == CAPI_INTEROPERABILITY) { in cmtp_recv_capimsg()
318 if (session->flags & BIT(CMTP_LOOPBACK)) { in cmtp_recv_capimsg()
323 appl = CAPIMSG_APPID(skb->data); in cmtp_recv_capimsg()
324 contr = CAPIMSG_CONTROL(skb->data); in cmtp_recv_capimsg()
328 appl = application->appl; in cmtp_recv_capimsg()
329 CAPIMSG_SETAPPID(skb->data, appl); in cmtp_recv_capimsg()
337 contr = (contr & 0xffffff80) | session->num; in cmtp_recv_capimsg()
338 CAPIMSG_SETCONTROL(skb->data, contr); in cmtp_recv_capimsg()
341 capi_ctr_handle_message(ctrl, appl, skb); in cmtp_recv_capimsg()
344 static int cmtp_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) in cmtp_load_firmware() argument
346 BT_DBG("ctrl %p data %p", ctrl, data); in cmtp_load_firmware()
351 static void cmtp_reset_ctr(struct capi_ctr *ctrl) in cmtp_reset_ctr() argument
353 struct cmtp_session *session = ctrl->driverdata; in cmtp_reset_ctr()
355 BT_DBG("ctrl %p", ctrl); in cmtp_reset_ctr()
357 capi_ctr_down(ctrl); in cmtp_reset_ctr()
359 atomic_inc(&session->terminate); in cmtp_reset_ctr()
360 wake_up_process(session->task); in cmtp_reset_ctr()
363 static void cmtp_register_appl(struct capi_ctr *ctrl, __u16 appl, capi_register_params *rp) in cmtp_register_appl() argument
366 struct cmtp_session *session = ctrl->driverdata; in cmtp_register_appl()
370 int err = 0, nconn, want = rp->level3cnt; in cmtp_register_appl()
372 BT_DBG("ctrl %p appl %u level3cnt %u datablkcnt %u datablklen %u", in cmtp_register_appl()
373 ctrl, appl, rp->level3cnt, rp->datablkcnt, rp->datablklen); in cmtp_register_appl()
382 nconn = ctrl->profile.nbchannel * -want; in cmtp_register_appl()
387 nconn = ctrl->profile.nbchannel; in cmtp_register_appl()
390 capimsg_setu16(buf, 2, rp->datablkcnt); in cmtp_register_appl()
391 capimsg_setu16(buf, 4, rp->datablklen); in cmtp_register_appl()
393 application->state = BT_CONFIG; in cmtp_register_appl()
394 application->msgnum = cmtp_msgnum_get(session); in cmtp_register_appl()
396 cmtp_send_interopmsg(session, CAPI_REQ, 0x0000, application->msgnum, in cmtp_register_appl()
399 add_wait_queue(&session->wait, &wait); in cmtp_register_appl()
404 err = -EAGAIN; in cmtp_register_appl()
408 if (application->state == BT_CLOSED) { in cmtp_register_appl()
409 err = -application->err; in cmtp_register_appl()
413 if (application->state == BT_CONNECTED) in cmtp_register_appl()
417 err = -EINTR; in cmtp_register_appl()
424 remove_wait_queue(&session->wait, &wait); in cmtp_register_appl()
432 static void cmtp_release_appl(struct capi_ctr *ctrl, __u16 appl) in cmtp_release_appl() argument
434 struct cmtp_session *session = ctrl->driverdata; in cmtp_release_appl()
437 BT_DBG("ctrl %p appl %u", ctrl, appl); in cmtp_release_appl()
445 application->msgnum = cmtp_msgnum_get(session); in cmtp_release_appl()
447 cmtp_send_interopmsg(session, CAPI_REQ, application->mapping, application->msgnum, in cmtp_release_appl()
450 wait_event_interruptible_timeout(session->wait, in cmtp_release_appl()
451 (application->state == BT_CLOSED), CMTP_INTEROP_TIMEOUT); in cmtp_release_appl()
456 static u16 cmtp_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) in cmtp_send_message() argument
458 struct cmtp_session *session = ctrl->driverdata; in cmtp_send_message()
463 BT_DBG("ctrl %p skb %p", ctrl, skb); in cmtp_send_message()
465 appl = CAPIMSG_APPID(skb->data); in cmtp_send_message()
466 contr = CAPIMSG_CONTROL(skb->data); in cmtp_send_message()
469 if ((!application) || (application->state != BT_CONNECTED)) { in cmtp_send_message()
474 CAPIMSG_SETAPPID(skb->data, application->mapping); in cmtp_send_message()
476 if ((contr & 0x7f) == session->num) { in cmtp_send_message()
478 CAPIMSG_SETCONTROL(skb->data, contr); in cmtp_send_message()
486 static char *cmtp_procinfo(struct capi_ctr *ctrl) in cmtp_procinfo() argument
493 struct capi_ctr *ctrl = m->private; in cmtp_proc_show() local
494 struct cmtp_session *session = ctrl->driverdata; in cmtp_proc_show()
497 seq_printf(m, "%s\n\n", cmtp_procinfo(ctrl)); in cmtp_proc_show()
498 seq_printf(m, "addr %s\n", session->name); in cmtp_proc_show()
499 seq_printf(m, "ctrl %d\n", session->num); in cmtp_proc_show()
501 list_for_each_entry(app, &session->applications, list) { in cmtp_proc_show()
502 seq_printf(m, "appl %u -> %u\n", app->appl, app->mapping); in cmtp_proc_show()
520 ret = wait_event_interruptible_timeout(session->wait, in cmtp_attach_device()
521 session->ncontroller, CMTP_INTEROP_TIMEOUT); in cmtp_attach_device()
523 BT_INFO("Found %d CAPI controller(s) on device %s", session->ncontroller, session->name); in cmtp_attach_device()
526 return -ETIMEDOUT; in cmtp_attach_device()
528 if (!session->ncontroller) in cmtp_attach_device()
529 return -ENODEV; in cmtp_attach_device()
531 if (session->ncontroller > 1) in cmtp_attach_device()
534 session->ctrl.owner = THIS_MODULE; in cmtp_attach_device()
535 session->ctrl.driverdata = session; in cmtp_attach_device()
536 strcpy(session->ctrl.name, session->name); in cmtp_attach_device()
538 session->ctrl.driver_name = "cmtp"; in cmtp_attach_device()
539 session->ctrl.load_firmware = cmtp_load_firmware; in cmtp_attach_device()
540 session->ctrl.reset_ctr = cmtp_reset_ctr; in cmtp_attach_device()
541 session->ctrl.register_appl = cmtp_register_appl; in cmtp_attach_device()
542 session->ctrl.release_appl = cmtp_release_appl; in cmtp_attach_device()
543 session->ctrl.send_message = cmtp_send_message; in cmtp_attach_device()
545 session->ctrl.procinfo = cmtp_procinfo; in cmtp_attach_device()
546 session->ctrl.proc_show = cmtp_proc_show; in cmtp_attach_device()
548 if (attach_capi_ctr(&session->ctrl) < 0) { in cmtp_attach_device()
550 return -EBUSY; in cmtp_attach_device()
553 session->num = session->ctrl.cnr; in cmtp_attach_device()
555 BT_DBG("session %p num %d", session, session->num); in cmtp_attach_device()
578 detach_capi_ctr(&session->ctrl); in cmtp_detach_device()