23 #include <linux/module.h>
26 #include <linux/types.h>
27 #include <linux/errno.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/poll.h>
32 #include <linux/fcntl.h>
34 #include <linux/socket.h>
37 #include <linux/wait.h>
47 #define CAPI_INTEROPERABILITY 0x20
49 #define CAPI_INTEROPERABILITY_REQ CAPICMD(CAPI_INTEROPERABILITY, CAPI_REQ)
50 #define CAPI_INTEROPERABILITY_CONF CAPICMD(CAPI_INTEROPERABILITY, CAPI_CONF)
51 #define CAPI_INTEROPERABILITY_IND CAPICMD(CAPI_INTEROPERABILITY, CAPI_IND)
52 #define CAPI_INTEROPERABILITY_RESP CAPICMD(CAPI_INTEROPERABILITY, CAPI_RESP)
54 #define CAPI_INTEROPERABILITY_REQ_LEN (CAPI_MSG_BASELEN + 2)
55 #define CAPI_INTEROPERABILITY_CONF_LEN (CAPI_MSG_BASELEN + 4)
56 #define CAPI_INTEROPERABILITY_IND_LEN (CAPI_MSG_BASELEN + 2)
57 #define CAPI_INTEROPERABILITY_RESP_LEN (CAPI_MSG_BASELEN + 2)
59 #define CAPI_FUNCTION_REGISTER 0
60 #define CAPI_FUNCTION_RELEASE 1
61 #define CAPI_FUNCTION_GET_PROFILE 2
62 #define CAPI_FUNCTION_GET_MANUFACTURER 3
63 #define CAPI_FUNCTION_GET_VERSION 4
64 #define CAPI_FUNCTION_GET_SERIAL_NUMBER 5
65 #define CAPI_FUNCTION_MANUFACTURER 6
66 #define CAPI_FUNCTION_LOOPBACK 7
71 #define CMTP_MAPPING 3
77 BT_DBG(
"session %p application %p appl %d", session, app, appl);
92 BT_DBG(
"session %p application %p", session, app);
113 if (app->
appl == value)
126 static int cmtp_msgnum_get(
struct cmtp_session *session)
130 if ((session->
msgnum & 0xff) > 200)
140 BT_DBG(
"session %p skb %p len %d", session, skb, skb->
len);
150 static void cmtp_send_interopmsg(
struct cmtp_session *session,
152 __u16 function,
unsigned char *
buf,
int len)
157 BT_DBG(
"session %p subcmd 0x%02x appl %d msgnum %d", session, subcmd, appl, msgnum);
161 BT_ERR(
"Can't allocate memory for interoperability packet");
168 capimsg_setu16(s, 2, appl);
170 capimsg_setu8 (s, 5, subcmd);
171 capimsg_setu16(s, 6, msgnum);
174 capimsg_setu16(s, 8, 0x0001);
176 capimsg_setu8 (s, 10, 3 + len);
177 capimsg_setu16(s, 11,
function);
178 capimsg_setu8 (s, 13, len);
183 cmtp_send_capimsg(session, skb);
193 BT_DBG(
"session %p skb %p len %d", session, skb, skb->
len);
207 application = cmtp_application_get(session,
CMTP_MSGNUM, msgnum);
220 application = cmtp_application_get(session,
CMTP_MAPPING, appl);
315 cmtp_send_interopmsg(session,
CAPI_RESP, appl, msgnum, func,
332 BT_DBG(
"session %p skb %p len %d", session, skb, skb->
len);
338 cmtp_recv_interopmsg(session, skb);
350 application = cmtp_application_get(session,
CMTP_MAPPING, appl);
352 appl = application->
appl;
355 BT_ERR(
"Can't find application with id %d", appl);
360 if ((contr & 0x7f) == 0x01) {
361 contr = (contr & 0xffffff80) | session->
num;
366 BT_ERR(
"Can't find controller %d for message", session->
num);
376 BT_DBG(
"ctrl %p data %p", ctrl, data);
381 static void cmtp_reset_ctr(
struct capi_ctr *ctrl)
399 unsigned char buf[8];
402 BT_DBG(
"ctrl %p appl %d level3cnt %d datablkcnt %d datablklen %d",
405 application = cmtp_application_add(session, appl);
407 BT_ERR(
"Can't allocate memory for new application");
419 capimsg_setu16(buf, 0, nconn);
424 application->
msgnum = cmtp_msgnum_get(session);
426 cmtp_send_interopmsg(session,
CAPI_REQ, 0x0000, application->
msgnum,
439 err = -application->
err;
457 cmtp_application_del(session, application);
462 static void cmtp_release_appl(
struct capi_ctr *ctrl,
__u16 appl)
467 BT_DBG(
"ctrl %p appl %d", ctrl, appl);
469 application = cmtp_application_get(session,
CMTP_APPLID, appl);
471 BT_ERR(
"Can't find application");
475 application->
msgnum = cmtp_msgnum_get(session);
483 cmtp_application_del(session, application);
493 BT_DBG(
"ctrl %p skb %p", ctrl, skb);
498 application = cmtp_application_get(session,
CMTP_APPLID, appl);
500 BT_ERR(
"Can't find application with id %d", appl);
506 if ((contr & 0x7f) == session->
num) {
507 contr = (contr & 0xffffff80) | 0x01;
511 cmtp_send_capimsg(session, skb);
516 static char *cmtp_procinfo(
struct capi_ctr *ctrl)
518 return "CAPI Message Transport Protocol";
521 static int cmtp_proc_show(
struct seq_file *
m,
void *
v)
547 .open = cmtp_proc_open,
555 unsigned char buf[4];
558 BT_DBG(
"session %p", session);
560 capimsg_setu32(buf, 0, 0);
577 BT_INFO(
"Setting up only CAPI controller 1");
580 session->
ctrl.driverdata = session;
583 session->
ctrl.driver_name =
"cmtp";
584 session->
ctrl.load_firmware = cmtp_load_firmware;
585 session->
ctrl.reset_ctr = cmtp_reset_ctr;
586 session->
ctrl.register_appl = cmtp_register_appl;
587 session->
ctrl.release_appl = cmtp_release_appl;
588 session->
ctrl.send_message = cmtp_send_message;
590 session->
ctrl.procinfo = cmtp_procinfo;
591 session->
ctrl.proc_fops = &cmtp_proc_fops;
594 BT_ERR(
"Can't attach new controller");
598 session->
num = session->
ctrl.cnr;
600 BT_DBG(
"session %p num %d", session, session->
num);
602 capimsg_setu32(buf, 0, 1);
604 cmtp_send_interopmsg(session,
CAPI_REQ, 0xffff, cmtp_msgnum_get(session),
607 cmtp_send_interopmsg(session,
CAPI_REQ, 0xffff, cmtp_msgnum_get(session),
610 cmtp_send_interopmsg(session,
CAPI_REQ, 0xffff, cmtp_msgnum_get(session),
613 cmtp_send_interopmsg(session,
CAPI_REQ, 0xffff, cmtp_msgnum_get(session),
621 BT_DBG(
"session %p", session);