1 /* $Id: command.c,v 1.4.10.1 2001/09/23 22:24:59 kai Exp $
3 * Copyright (C) 1996 SpellCaster Telecommunications Inc.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * For more information, please contact gpl-info@spellcast.com or write:
10 * SpellCaster Telecommunications Inc.
11 * 5621 Finch Avenue East, Unit #3
12 * Scarborough, Ontario Canada
15 * +1 (416) 297-6433 Facsimile
18 #include <linux/module.h>
19 #include "includes.h" /* This must be first */
25 int dial(int card
, unsigned long channel
, setup_parm setup
);
26 int hangup(int card
, unsigned long channel
);
27 int answer(int card
, unsigned long channel
);
28 int clreaz(int card
, unsigned long channel
);
29 int seteaz(int card
, unsigned long channel
, char *);
30 int setl2(int card
, unsigned long arg
);
31 int setl3(int card
, unsigned long arg
);
32 int acceptb(int card
, unsigned long channel
);
35 extern board
*sc_adapter
[];
37 extern int sc_ioctl(int, scs_ioctl
*);
38 extern int setup_buffers(int, int, unsigned int);
39 extern int indicate_status(int, int,ulong
,char*);
40 extern void check_reset(unsigned long);
41 extern int send_and_receive(int, unsigned int, unsigned char, unsigned char,
42 unsigned char, unsigned char, unsigned char, unsigned char *,
44 extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
45 unsigned int, unsigned int, unsigned int, unsigned int *);
46 extern inline void pullphone(char *, char *);
50 * Translate command codes to strings
52 static char *commands
[] = { "ISDN_CMD_IOCTL",
72 * Translates ISDN4Linux protocol codes to strings for debug messages
74 static char *l3protos
[] = { "ISDN_PROTO_L3_TRANS" };
75 static char *l2protos
[] = { "ISDN_PROTO_L2_X75I",
76 "ISDN_PROTO_L2_X75UI",
77 "ISDN_PROTO_L2_X75BUI",
79 "ISDN_PROTO_L2_TRANS" };
82 int get_card_from_id(int driver
)
86 for(i
= 0 ; i
< cinst
; i
++) {
87 if(sc_adapter
[i
]->driverId
== driver
)
97 int command(isdn_ctrl
*cmd
)
101 card
= get_card_from_id(cmd
->driver
);
102 if(!IS_VALID_CARD(card
)) {
103 pr_debug("Invalid param: %d is not a valid card id\n", card
);
107 pr_debug("%s: Received %s command from Link Layer\n",
108 sc_adapter
[card
]->devicename
, commands
[cmd
->command
]);
111 * Dispatch the command
113 switch(cmd
->command
) {
116 unsigned long cmdptr
;
119 memcpy(&cmdptr
, cmd
->parm
.num
, sizeof(unsigned long));
120 if (copy_from_user(&ioc
, (scs_ioctl __user
*)cmdptr
,
121 sizeof(scs_ioctl
))) {
122 pr_debug("%s: Failed to verify user space 0x%x\n",
123 sc_adapter
[card
]->devicename
, cmdptr
);
126 return sc_ioctl(card
, &ioc
);
129 return dial(card
, cmd
->arg
, cmd
->parm
.setup
);
130 case ISDN_CMD_HANGUP
:
131 return hangup(card
, cmd
->arg
);
132 case ISDN_CMD_ACCEPTD
:
133 return answer(card
, cmd
->arg
);
134 case ISDN_CMD_ACCEPTB
:
135 return acceptb(card
, cmd
->arg
);
136 case ISDN_CMD_CLREAZ
:
137 return clreaz(card
, cmd
->arg
);
138 case ISDN_CMD_SETEAZ
:
139 return seteaz(card
, cmd
->arg
, cmd
->parm
.num
);
141 return setl2(card
, cmd
->arg
);
143 return setl3(card
, cmd
->arg
);
151 * Confirm our ability to communicate with the board. This test assumes no
152 * other message activity is present
154 int loopback(int card
)
158 static char testmsg
[] = "Test Message";
161 if(!IS_VALID_CARD(card
)) {
162 pr_debug("Invalid param: %d is not a valid card id\n", card
);
166 pr_debug("%s: Sending loopback message\n",
167 sc_adapter
[card
]->devicename
);
170 * Send the loopback message to confirm that memory transfer is
173 status
= send_and_receive(card
, CMPID
, cmReqType1
,
177 (unsigned char) strlen(testmsg
),
178 (unsigned char *)testmsg
,
179 &rspmsg
, SAR_TIMEOUT
);
183 pr_debug("%s: Loopback message successfully sent\n",
184 sc_adapter
[card
]->devicename
);
185 if(strcmp(rspmsg
.msg_data
.byte_array
, testmsg
)) {
186 pr_debug("%s: Loopback return != sent\n",
187 sc_adapter
[card
]->devicename
);
193 pr_debug("%s: Send loopback message failed\n",
194 sc_adapter
[card
]->devicename
);
201 * start the onboard firmware
203 int startproc(int card
)
207 if(!IS_VALID_CARD(card
)) {
208 pr_debug("Invalid param: %d is not a valid card id\n", card
);
215 status
= sendmessage(card
, CMPID
,cmReqType2
,
219 pr_debug("%s: Sent startProc\n", sc_adapter
[card
]->devicename
);
225 int loadproc(int card
, char *data
)
232 * Dials the number passed in
234 int dial(int card
, unsigned long channel
, setup_parm setup
)
239 if(!IS_VALID_CARD(card
)) {
240 pr_debug("Invalid param: %d is not a valid card id\n", card
);
244 /*extract ISDN number to dial from eaz/msn string*/
245 strcpy(Phone
,setup
.phone
);
247 /*send the connection message*/
248 status
= sendmessage(card
, CEPID
,ceReqTypePhy
,
251 (unsigned char) channel
+1,
253 (unsigned int *) Phone
);
255 pr_debug("%s: Dialing %s on channel %d\n",
256 sc_adapter
[card
]->devicename
, Phone
, channel
+1);
262 * Answer an incoming call
264 int answer(int card
, unsigned long channel
)
266 if(!IS_VALID_CARD(card
)) {
267 pr_debug("Invalid param: %d is not a valid card id\n", card
);
271 if(setup_buffers(card
, channel
+1, BUFFER_SIZE
)) {
272 hangup(card
, channel
+1);
276 indicate_status(card
, ISDN_STAT_BCONN
,channel
,NULL
);
277 pr_debug("%s: Answered incoming call on channel %s\n",
278 sc_adapter
[card
]->devicename
, channel
+1);
283 * Hangup up the call on specified channel
285 int hangup(int card
, unsigned long channel
)
289 if(!IS_VALID_CARD(card
)) {
290 pr_debug("Invalid param: %d is not a valid card id\n", card
);
294 status
= sendmessage(card
, CEPID
, ceReqTypePhy
,
297 (unsigned char) channel
+1,
300 pr_debug("%s: Sent HANGUP message to channel %d\n",
301 sc_adapter
[card
]->devicename
, channel
+1);
306 * Set the layer 2 protocol (X.25, HDLC, Raw)
308 int setl2(int card
, unsigned long arg
)
311 int protocol
,channel
;
313 if(!IS_VALID_CARD(card
)) {
314 pr_debug("Invalid param: %d is not a valid card id\n", card
);
318 channel
= arg
& 0xff;
319 sc_adapter
[card
]->channel
[channel
].l2_proto
= protocol
;
320 pr_debug("%s: Level 2 protocol for channel %d set to %s from %d\n",
321 sc_adapter
[card
]->devicename
, channel
+1,
322 l2protos
[sc_adapter
[card
]->channel
[channel
].l2_proto
],protocol
);
325 * check that the adapter is also set to the correct protocol
327 pr_debug("%s: Sending GetFrameFormat for channel %d\n",
328 sc_adapter
[card
]->devicename
, channel
+1);
329 status
= sendmessage(card
, CEPID
, ceReqTypeCall
,
331 ceReqCallGetFrameFormat
,
332 (unsigned char)channel
+1,
334 (unsigned int *) protocol
);
341 * Set the layer 3 protocol
343 int setl3(int card
, unsigned long channel
)
345 int protocol
= channel
>> 8;
347 if(!IS_VALID_CARD(card
)) {
348 pr_debug("Invalid param: %d is not a valid card id\n", card
);
352 sc_adapter
[card
]->channel
[channel
].l3_proto
= protocol
;
353 pr_debug("%s: Level 3 protocol for channel %d set to %s\n",
354 sc_adapter
[card
]->devicename
, channel
+1, l3protos
[protocol
]);
358 int acceptb(int card
, unsigned long channel
)
360 if(!IS_VALID_CARD(card
)) {
361 pr_debug("Invalid param: %d is not a valid card id\n", card
);
365 if(setup_buffers(card
, channel
+1, BUFFER_SIZE
))
367 hangup(card
, channel
+1);
371 pr_debug("%s: B-Channel connection accepted on channel %d\n",
372 sc_adapter
[card
]->devicename
, channel
+1);
373 indicate_status(card
, ISDN_STAT_BCONN
, channel
, NULL
);
377 int clreaz(int card
, unsigned long arg
)
379 if(!IS_VALID_CARD(card
)) {
380 pr_debug("Invalid param: %d is not a valid card id\n", card
);
384 strcpy(sc_adapter
[card
]->channel
[arg
].eazlist
, "");
385 sc_adapter
[card
]->channel
[arg
].eazclear
= 1;
386 pr_debug("%s: EAZ List cleared for channel %d\n",
387 sc_adapter
[card
]->devicename
, arg
+1);
391 int seteaz(int card
, unsigned long arg
, char *num
)
393 if(!IS_VALID_CARD(card
)) {
394 pr_debug("Invalid param: %d is not a valid card id\n", card
);
398 strcpy(sc_adapter
[card
]->channel
[arg
].eazlist
, num
);
399 sc_adapter
[card
]->channel
[arg
].eazclear
= 0;
400 pr_debug("%s: EAZ list for channel %d set to: %s\n",
401 sc_adapter
[card
]->devicename
, arg
+1,
402 sc_adapter
[card
]->channel
[arg
].eazlist
);
410 if(!IS_VALID_CARD(card
)) {
411 pr_debug("Invalid param: %d is not a valid card id\n", card
);
415 indicate_status(card
, ISDN_STAT_STOP
, 0, NULL
);
417 if(sc_adapter
[card
]->EngineUp
) {
418 del_timer(&sc_adapter
[card
]->stat_timer
);
421 sc_adapter
[card
]->EngineUp
= 0;
423 spin_lock_irqsave(&sc_adapter
[card
]->lock
, flags
);
424 init_timer(&sc_adapter
[card
]->reset_timer
);
425 sc_adapter
[card
]->reset_timer
.function
= check_reset
;
426 sc_adapter
[card
]->reset_timer
.data
= card
;
427 sc_adapter
[card
]->reset_timer
.expires
= jiffies
+ CHECKRESET_TIME
;
428 add_timer(&sc_adapter
[card
]->reset_timer
);
429 spin_unlock_irqrestore(&sc_adapter
[card
]->lock
, flags
);
431 outb(0x1,sc_adapter
[card
]->ioport
[SFT_RESET
]);
433 pr_debug("%s: Adapter Reset\n", sc_adapter
[card
]->devicename
);
437 void flushreadfifo (int card
)
439 while(inb(sc_adapter
[card
]->ioport
[FIFO_STATUS
]) & RF_HAS_DATA
)
440 inb(sc_adapter
[card
]->ioport
[FIFO_READ
]);