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 static int dial(int card, unsigned long channel, setup_parm setup);
26 static int hangup(int card, unsigned long channel);
27 static int answer(int card, unsigned long channel);
28 static int clreaz(int card, unsigned long channel);
29 static int seteaz(int card, unsigned long channel, char *);
30 static int setl2(int card, unsigned long arg);
31 static int setl3(int card, unsigned long arg);
32 static 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 *);
49 * Translate command codes to strings
51 static char *commands[] = { "ISDN_CMD_IOCTL",
71 * Translates ISDN4Linux protocol codes to strings for debug messages
73 static char *l3protos[] = { "ISDN_PROTO_L3_TRANS" };
74 static char *l2protos[] = { "ISDN_PROTO_L2_X75I",
75 "ISDN_PROTO_L2_X75UI",
76 "ISDN_PROTO_L2_X75BUI",
78 "ISDN_PROTO_L2_TRANS" };
81 int get_card_from_id(int driver)
85 for(i = 0 ; i < cinst ; i++) {
86 if(sc_adapter[i]->driverId == driver)
96 int command(isdn_ctrl *cmd)
100 card = get_card_from_id(cmd->driver);
101 if(!IS_VALID_CARD(card)) {
102 pr_debug("Invalid param: %d is not a valid card id\n", card);
107 * Dispatch the command
109 switch(cmd->command) {
112 unsigned long cmdptr;
115 memcpy(&cmdptr, cmd->parm.num, sizeof(unsigned long));
116 if (copy_from_user(&ioc, (scs_ioctl __user *)cmdptr,
117 sizeof(scs_ioctl))) {
118 pr_debug("%s: Failed to verify user space 0x%lx\n",
119 sc_adapter[card]->devicename, cmdptr);
122 return sc_ioctl(card, &ioc);
125 return dial(card, cmd->arg, cmd->parm.setup);
126 case ISDN_CMD_HANGUP:
127 return hangup(card, cmd->arg);
128 case ISDN_CMD_ACCEPTD:
129 return answer(card, cmd->arg);
130 case ISDN_CMD_ACCEPTB:
131 return acceptb(card, cmd->arg);
132 case ISDN_CMD_CLREAZ:
133 return clreaz(card, cmd->arg);
134 case ISDN_CMD_SETEAZ:
135 return seteaz(card, cmd->arg, cmd->parm.num);
137 return setl2(card, cmd->arg);
139 return setl3(card, cmd->arg);
147 * start the onboard firmware
149 int startproc(int card)
153 if(!IS_VALID_CARD(card)) {
154 pr_debug("Invalid param: %d is not a valid card id\n", card);
161 status = sendmessage(card, CMPID,cmReqType2,
165 pr_debug("%s: Sent startProc\n", sc_adapter[card]->devicename);
172 * Dials the number passed in
174 static int dial(int card, unsigned long channel, setup_parm setup)
179 if(!IS_VALID_CARD(card)) {
180 pr_debug("Invalid param: %d is not a valid card id\n", card);
184 /*extract ISDN number to dial from eaz/msn string*/
185 strcpy(Phone,setup.phone);
187 /*send the connection message*/
188 status = sendmessage(card, CEPID,ceReqTypePhy,
191 (unsigned char) channel+1,
193 (unsigned int *) Phone);
195 pr_debug("%s: Dialing %s on channel %lu\n",
196 sc_adapter[card]->devicename, Phone, channel+1);
202 * Answer an incoming call
204 static int answer(int card, unsigned long channel)
206 if(!IS_VALID_CARD(card)) {
207 pr_debug("Invalid param: %d is not a valid card id\n", card);
211 if(setup_buffers(card, channel+1, BUFFER_SIZE)) {
212 hangup(card, channel+1);
216 indicate_status(card, ISDN_STAT_BCONN,channel,NULL);
217 pr_debug("%s: Answered incoming call on channel %lu\n",
218 sc_adapter[card]->devicename, channel+1);
223 * Hangup up the call on specified channel
225 static int hangup(int card, unsigned long channel)
229 if(!IS_VALID_CARD(card)) {
230 pr_debug("Invalid param: %d is not a valid card id\n", card);
234 status = sendmessage(card, CEPID, ceReqTypePhy,
237 (unsigned char) channel+1,
240 pr_debug("%s: Sent HANGUP message to channel %lu\n",
241 sc_adapter[card]->devicename, channel+1);
246 * Set the layer 2 protocol (X.25, HDLC, Raw)
248 static int setl2(int card, unsigned long arg)
251 int protocol,channel;
253 if(!IS_VALID_CARD(card)) {
254 pr_debug("Invalid param: %d is not a valid card id\n", card);
258 channel = arg & 0xff;
259 sc_adapter[card]->channel[channel].l2_proto = protocol;
262 * check that the adapter is also set to the correct protocol
264 pr_debug("%s: Sending GetFrameFormat for channel %d\n",
265 sc_adapter[card]->devicename, channel+1);
266 status = sendmessage(card, CEPID, ceReqTypeCall,
268 ceReqCallGetFrameFormat,
269 (unsigned char)channel+1,
271 (unsigned int *) protocol);
278 * Set the layer 3 protocol
280 static int setl3(int card, unsigned long channel)
282 int protocol = channel >> 8;
284 if(!IS_VALID_CARD(card)) {
285 pr_debug("Invalid param: %d is not a valid card id\n", card);
289 sc_adapter[card]->channel[channel].l3_proto = protocol;
293 static int acceptb(int card, unsigned long channel)
295 if(!IS_VALID_CARD(card)) {
296 pr_debug("Invalid param: %d is not a valid card id\n", card);
300 if(setup_buffers(card, channel+1, BUFFER_SIZE))
302 hangup(card, channel+1);
306 pr_debug("%s: B-Channel connection accepted on channel %lu\n",
307 sc_adapter[card]->devicename, channel+1);
308 indicate_status(card, ISDN_STAT_BCONN, channel, NULL);
312 static int clreaz(int card, unsigned long arg)
314 if(!IS_VALID_CARD(card)) {
315 pr_debug("Invalid param: %d is not a valid card id\n", card);
319 strcpy(sc_adapter[card]->channel[arg].eazlist, "");
320 sc_adapter[card]->channel[arg].eazclear = 1;
321 pr_debug("%s: EAZ List cleared for channel %lu\n",
322 sc_adapter[card]->devicename, arg+1);
326 static int seteaz(int card, unsigned long arg, char *num)
328 if(!IS_VALID_CARD(card)) {
329 pr_debug("Invalid param: %d is not a valid card id\n", card);
333 strcpy(sc_adapter[card]->channel[arg].eazlist, num);
334 sc_adapter[card]->channel[arg].eazclear = 0;
335 pr_debug("%s: EAZ list for channel %lu set to: %s\n",
336 sc_adapter[card]->devicename, arg+1,
337 sc_adapter[card]->channel[arg].eazlist);
345 if(!IS_VALID_CARD(card)) {
346 pr_debug("Invalid param: %d is not a valid card id\n", card);
350 indicate_status(card, ISDN_STAT_STOP, 0, NULL);
352 if(sc_adapter[card]->EngineUp) {
353 del_timer(&sc_adapter[card]->stat_timer);
356 sc_adapter[card]->EngineUp = 0;
358 spin_lock_irqsave(&sc_adapter[card]->lock, flags);
359 init_timer(&sc_adapter[card]->reset_timer);
360 sc_adapter[card]->reset_timer.function = check_reset;
361 sc_adapter[card]->reset_timer.data = card;
362 sc_adapter[card]->reset_timer.expires = jiffies + CHECKRESET_TIME;
363 add_timer(&sc_adapter[card]->reset_timer);
364 spin_unlock_irqrestore(&sc_adapter[card]->lock, flags);
366 outb(0x1,sc_adapter[card]->ioport[SFT_RESET]);
368 pr_debug("%s: Adapter Reset\n", sc_adapter[card]->devicename);
372 void flushreadfifo (int card)
374 while(inb(sc_adapter[card]->ioport[FIFO_STATUS]) & RF_HAS_DATA)
375 inb(sc_adapter[card]->ioport[FIFO_READ]);