2 * Asterisk -- A telephony toolkit for Linux.
4 * Use /dev/dsp as a channel, and the console to command it :).
6 * The full-duplex "simulation" is pretty weak. This is generally a
7 * VERY BADLY WRITTEN DRIVER so please don't use it as a model for
10 * Copyright (C) 1999 - 2005, Digium, Inc.
12 * Mark Spencer <markster@digium.com>
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License
18 #include <asterisk/lock.h>
19 #include <asterisk/frame.h>
20 #include <asterisk/logger.h>
21 #include <asterisk/channel.h>
22 #include <asterisk/module.h>
23 #include <asterisk/channel_pvt.h>
24 #include <asterisk/options.h>
25 #include <asterisk/pbx.h>
26 #include <asterisk/config.h>
27 #include <asterisk/cli.h>
28 #include <asterisk/utils.h>
29 #include <asterisk/causes.h>
33 #include <sys/ioctl.h>
39 #include <linux/soundcard.h>
40 #elif defined(__FreeBSD__)
41 #include <sys/soundcard.h>
43 #include <soundcard.h>
50 /* Which device to use */
51 #if defined( __OpenBSD__ ) || defined( __NetBSD__ )
52 #define DEV_DSP "/dev/audio"
54 #define DEV_DSP "/dev/dsp"
57 /* Lets use 160 sample frames, just like GSM. */
58 #define FRAME_SIZE 160
60 /* When you set the frame size, you have to come up with
61 the right buffer format as well. */
62 /* 5 64-byte frames = one frame */
63 #define BUFFER_FMT ((buffersize * 10) << 16) | (0x0006);
65 /* Don't switch between read/write modes faster than every 300 ms */
66 #define MIN_SWITCH_TIME 600
68 static struct timeval lasttime;
71 static int silencesuppression = 0;
72 static int silencethreshold = 1000;
75 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
77 static char *type = "Console";
78 static char *desc = "OSS Console Channel Driver";
79 static char *tdesc = "OSS Console Channel Driver";
80 static char *config = "oss.conf";
82 static char context[AST_MAX_EXTENSION] = "default";
83 static char language[MAX_LANGUAGE] = "";
84 static char exten[AST_MAX_EXTENSION] = "s";
86 static int hookstate=0;
88 static short silence[FRAME_SIZE] = {0, };
99 static struct sound sounds[] = {
100 { AST_CONTROL_RINGING, ringtone, sizeof(ringtone)/2, 16000, 32000, 1 },
101 { AST_CONTROL_BUSY, busy, sizeof(busy)/2, 4000, 4000, 1 },
102 { AST_CONTROL_CONGESTION, busy, sizeof(busy)/2, 2000, 2000, 1 },
103 { AST_CONTROL_RING, ring10, sizeof(ring10)/2, 16000, 32000, 1 },
104 { AST_CONTROL_ANSWER, answer, sizeof(answer)/2, 2200, 0, 0 },
107 /* Sound command pipe */
108 static int sndcmd[2];
110 static struct chan_oss_pvt {
111 /* We only have one OSS structure -- near sighted perhaps, but it
112 keeps this driver as simple as possible -- as it should be. */
113 struct ast_channel *owner;
114 char exten[AST_MAX_EXTENSION];
115 char context[AST_MAX_EXTENSION];
118 static int time_has_passed(void)
122 gettimeofday(&tv, NULL);
123 ms = (tv.tv_sec - lasttime.tv_sec) * 1000 +
124 (tv.tv_usec - lasttime.tv_usec) / 1000;
125 if (ms > MIN_SWITCH_TIME)
130 /* Number of buffers... Each is FRAMESIZE/8 ms long. For example
131 with 160 sample frames, and a buffer size of 3, we have a 60ms buffer,
134 static pthread_t sthread;
136 #define MAX_BUFFER_SIZE 100
137 static int buffersize = 3;
139 static int full_duplex = 0;
141 /* Are we reading or writing (simulated full duplex) */
142 static int readmode = 1;
144 /* File descriptor for sound device */
145 static int sounddev = -1;
147 static int autoanswer = 1;
150 static int calc_loudness(short *frame)
154 for (x=0;x<FRAME_SIZE;x++) {
160 sum = sum/FRAME_SIZE;
165 static int cursound = -1;
166 static int sampsent = 0;
167 static int silencelen=0;
169 static int nosound=0;
171 static int send_sound(void)
173 short myframe[FRAME_SIZE];
174 int total = FRAME_SIZE;
181 res = ioctl(sounddev, SNDCTL_DSP_GETOSPACE ,&abi);
183 ast_log(LOG_WARNING, "Unable to read output space\n");
186 /* Calculate how many samples we can send, max */
187 if (total > (abi.fragments * abi.fragsize / 2))
188 total = abi.fragments * abi.fragsize / 2;
190 if (sampsent < sounds[cursound].samplen) {
194 if (amt > (sounds[cursound].datalen - offset))
195 amt = sounds[cursound].datalen - offset;
196 memcpy(myframe + myoff, sounds[cursound].data + offset, amt * 2);
201 if (offset >= sounds[cursound].datalen)
204 /* Set it up for silence */
205 if (sampsent >= sounds[cursound].samplen)
206 silencelen = sounds[cursound].silencelen;
209 if (silencelen > 0) {
213 if (sounds[cursound].repeat) {
224 res = write(sounddev, frame, res * 2);
232 static void *sound_thread(void *unused)
239 if (read(sounddev, ign, sizeof(sounddev)) < 0)
240 ast_log(LOG_WARNING, "Read error on sound device: %s\n", strerror(errno));
245 FD_SET(sndcmd[0], &rfds);
247 FD_SET(sounddev, &rfds);
252 FD_SET(sounddev, &wfds);
256 res = ast_select(max + 1, &rfds, &wfds, NULL, NULL);
258 ast_log(LOG_WARNING, "select failed: %s\n", strerror(errno));
261 if (FD_ISSET(sndcmd[0], &rfds)) {
262 read(sndcmd[0], &cursound, sizeof(cursound));
267 if (FD_ISSET(sounddev, &rfds)) {
269 if (read(sounddev, ign, sizeof(ign)) < 0)
270 ast_log(LOG_WARNING, "Read error on sound device: %s\n", strerror(errno));
272 if (FD_ISSET(sounddev, &wfds))
274 ast_log(LOG_WARNING, "Failed to write sound\n");
281 static int silence_suppress(short *buf)
285 static int silentframes = 0;
286 static char silbuf[FRAME_SIZE * 2 * SILBUF];
287 static int silbufcnt=0;
288 if (!silencesuppression)
290 loudness = calc_loudness((short *)(buf));
292 ast_log(LOG_DEBUG, "loudness is %d\n", loudness);
293 if (loudness < silencethreshold) {
296 /* Keep track of the last few bits of silence so we can play
297 them as lead-in when the time is right */
298 if (silbufcnt >= SILBUF) {
299 /* Make way for more buffer */
300 memmove(silbuf, silbuf + FRAME_SIZE * 2, FRAME_SIZE * 2 * (SILBUF - 1));
303 memcpy(silbuf + FRAME_SIZE * 2 * silbufcnt, buf, FRAME_SIZE * 2);
304 if (silentframes > 10) {
305 /* We've had plenty of silence, so compress it now */
310 /* Write any buffered silence we have, it may have something
313 write(sounddev, silbuf, silbufcnt * FRAME_SIZE);
321 static int setformat(void)
323 int fmt, desired, res, fd = sounddev;
324 static int warnedalready = 0;
325 static int warnedalready2 = 0;
327 res = ioctl(fd, SNDCTL_DSP_SETFMT, &fmt);
329 ast_log(LOG_WARNING, "Unable to set format to 16-bit signed\n");
332 res = ioctl(fd, SNDCTL_DSP_SETDUPLEX, 0);
334 /* Check to see if duplex set (FreeBSD Bug)*/
335 res = ioctl(fd, SNDCTL_DSP_GETCAPS, &fmt);
337 if ((fmt & DSP_CAP_DUPLEX) && !res) {
338 if (option_verbose > 1)
339 ast_verbose(VERBOSE_PREFIX_2 "Console is full duplex\n");
343 res = ioctl(fd, SNDCTL_DSP_STEREO, &fmt);
345 ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
348 /* 8000 Hz desired */
351 res = ioctl(fd, SNDCTL_DSP_SPEED, &fmt);
353 ast_log(LOG_WARNING, "Failed to set audio device to mono\n");
356 if (fmt != desired) {
357 if (!warnedalready++)
358 ast_log(LOG_WARNING, "Requested %d Hz, got %d Hz -- sound may be choppy\n", desired, fmt);
362 res = ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &fmt);
364 if (!warnedalready2++)
365 ast_log(LOG_WARNING, "Unable to set fragment size -- sound may be choppy\n");
371 static int soundcard_setoutput(int force)
373 /* Make sure the soundcard is in output mode. */
375 if (full_duplex || (!readmode && !force))
378 if (force || time_has_passed()) {
379 ioctl(sounddev, SNDCTL_DSP_RESET, 0);
380 /* Keep the same fd reserved by closing the sound device and copying stdin at the same
382 /* dup2(0, sound); */
384 fd = open(DEV_DSP, O_WRONLY |O_NONBLOCK);
386 ast_log(LOG_WARNING, "Unable to re-open DSP device: %s\n", strerror(errno));
389 /* dup2 will close the original and make fd be sound */
390 if (dup2(fd, sounddev) < 0) {
391 ast_log(LOG_WARNING, "dup2() failed: %s\n", strerror(errno));
402 static int soundcard_setinput(int force)
405 if (full_duplex || (readmode && !force))
408 if (force || time_has_passed()) {
409 ioctl(sounddev, SNDCTL_DSP_RESET, 0);
411 /* dup2(0, sound); */
412 fd = open(DEV_DSP, O_RDONLY | O_NONBLOCK);
414 ast_log(LOG_WARNING, "Unable to re-open DSP device: %s\n", strerror(errno));
417 /* dup2 will close the original and make fd be sound */
418 if (dup2(fd, sounddev) < 0) {
419 ast_log(LOG_WARNING, "dup2() failed: %s\n", strerror(errno));
430 static int soundcard_init(void)
432 /* Assume it's full duplex for starters */
433 int fd = open(DEV_DSP, O_RDWR | O_NONBLOCK);
435 ast_log(LOG_WARNING, "Unable to open %s: %s\n", DEV_DSP, strerror(errno));
438 gettimeofday(&lasttime, NULL);
442 soundcard_setinput(1);
446 static int oss_digit(struct ast_channel *c, char digit)
448 ast_verbose( " << Console Received digit %c >> \n", digit);
452 static int oss_text(struct ast_channel *c, char *text)
454 ast_verbose( " << Console Received text %s >> \n", text);
458 static int oss_call(struct ast_channel *c, char *dest, int timeout)
461 struct ast_frame f = { 0, };
462 ast_verbose( " << Call placed to '%s' on console >> \n", dest);
464 ast_verbose( " << Auto-answered >> \n" );
465 f.frametype = AST_FRAME_CONTROL;
466 f.subclass = AST_CONTROL_ANSWER;
467 ast_queue_frame(c, &f);
470 ast_verbose( " << Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
471 f.frametype = AST_FRAME_CONTROL;
472 f.subclass = AST_CONTROL_RINGING;
473 ast_queue_frame(c, &f);
474 write(sndcmd[1], &res, sizeof(res));
479 static void answer_sound(void)
484 write(sndcmd[1], &res, sizeof(res));
488 static int oss_answer(struct ast_channel *c)
490 ast_verbose( " << Console call has been answered >> \n");
492 ast_setstate(c, AST_STATE_UP);
498 static int oss_hangup(struct ast_channel *c)
504 ast_verbose( " << Hangup on console >> \n");
505 ast_mutex_lock(&usecnt_lock);
507 ast_mutex_unlock(&usecnt_lock);
510 /* Assume auto-hangup too */
513 /* Make congestion noise */
515 write(sndcmd[1], &res, sizeof(res));
521 static int soundcard_writeframe(short *data)
523 /* Write an exactly FRAME_SIZE sized of frame */
524 static int bufcnt = 0;
525 static short buffer[FRAME_SIZE * MAX_BUFFER_SIZE * 5];
526 struct audio_buf_info info;
530 if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &info)) {
532 ast_log(LOG_WARNING, "Error reading output space\n");
536 if ((info.fragments >= buffersize * 5) && (bufcnt == buffersize)) {
537 /* We've run out of stuff, buffer again */
540 if (bufcnt == buffersize) {
541 /* Write sample immediately */
542 res = write(fd, ((void *)data), FRAME_SIZE * 2);
544 /* Copy the data into our buffer */
545 res = FRAME_SIZE * 2;
546 memcpy(buffer + (bufcnt * FRAME_SIZE), data, FRAME_SIZE * 2);
548 if (bufcnt == buffersize) {
549 res = write(fd, ((void *)buffer), FRAME_SIZE * 2 * buffersize);
556 static int oss_write(struct ast_channel *chan, struct ast_frame *f)
559 static char sizbuf[8000];
560 static int sizpos = 0;
563 /* Immediately return if no sound is enabled */
566 /* Stop any currently playing sound */
569 /* If we're half duplex, we have to switch to read mode
570 to honor immediate needs if necessary */
571 res = soundcard_setinput(1);
573 ast_log(LOG_WARNING, "Unable to set device to input mode\n");
578 res = soundcard_setoutput(0);
580 ast_log(LOG_WARNING, "Unable to set output device\n");
582 } else if (res > 0) {
583 /* The device is still in read mode, and it's too soon to change it,
584 so just pretend we wrote it */
587 /* We have to digest the frame in 160-byte portions */
588 if (f->datalen > sizeof(sizbuf) - sizpos) {
589 ast_log(LOG_WARNING, "Frame too large\n");
592 memcpy(sizbuf + sizpos, f->data, f->datalen);
595 while(len - pos > FRAME_SIZE * 2) {
596 soundcard_writeframe((short *)(sizbuf + pos));
597 pos += FRAME_SIZE * 2;
600 memmove(sizbuf, sizbuf + pos, len - pos);
605 static struct ast_frame *oss_read(struct ast_channel *chan)
607 static struct ast_frame f;
608 static char buf[FRAME_SIZE * 2 + AST_FRIENDLY_OFFSET];
609 static int readpos = 0;
613 ast_log(LOG_DEBUG, "oss_read()\n");
616 f.frametype = AST_FRAME_NULL;
624 f.delivery.tv_sec = 0;
625 f.delivery.tv_usec = 0;
627 res = soundcard_setinput(0);
629 ast_log(LOG_WARNING, "Unable to set input mode\n");
633 /* Theoretically shouldn't happen, but anyway, return a NULL frame */
636 res = read(sounddev, buf + AST_FRIENDLY_OFFSET + readpos, FRAME_SIZE * 2 - readpos);
638 ast_log(LOG_WARNING, "Error reading from sound device (If you're running 'artsd' then kill it): %s\n", strerror(errno));
646 if (readpos >= FRAME_SIZE * 2) {
649 if (chan->_state != AST_STATE_UP) {
650 /* Don't transmit unless it's up */
653 f.frametype = AST_FRAME_VOICE;
654 f.subclass = AST_FORMAT_SLINEAR;
655 f.samples = FRAME_SIZE;
656 f.datalen = FRAME_SIZE * 2;
657 f.data = buf + AST_FRIENDLY_OFFSET;
658 f.offset = AST_FRIENDLY_OFFSET;
661 f.delivery.tv_sec = 0;
662 f.delivery.tv_usec = 0;
664 { static int fd = -1;
666 fd = open("output.raw", O_RDWR | O_TRUNC | O_CREAT);
667 write(fd, f.data, f.datalen);
674 static int oss_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
676 struct chan_oss_pvt *p = newchan->pvt->pvt;
681 static int oss_indicate(struct ast_channel *chan, int cond)
685 case AST_CONTROL_BUSY:
688 case AST_CONTROL_CONGESTION:
691 case AST_CONTROL_RINGING:
698 ast_log(LOG_WARNING, "Don't know how to display condition %d on %s\n", cond, chan->name);
702 write(sndcmd[1], &res, sizeof(res));
707 static struct ast_channel *oss_new(struct chan_oss_pvt *p, int state)
709 struct ast_channel *tmp;
710 tmp = ast_channel_alloc(1);
712 snprintf(tmp->name, sizeof(tmp->name), "OSS/%s", DEV_DSP + 5);
714 tmp->fds[0] = sounddev;
715 tmp->nativeformats = AST_FORMAT_SLINEAR;
716 tmp->readformat = AST_FORMAT_SLINEAR;
717 tmp->writeformat = AST_FORMAT_SLINEAR;
719 tmp->pvt->send_digit = oss_digit;
720 tmp->pvt->send_text = oss_text;
721 tmp->pvt->hangup = oss_hangup;
722 tmp->pvt->answer = oss_answer;
723 tmp->pvt->read = oss_read;
724 tmp->pvt->call = oss_call;
725 tmp->pvt->write = oss_write;
726 tmp->pvt->indicate = oss_indicate;
727 tmp->pvt->fixup = oss_fixup;
728 if (strlen(p->context))
729 strncpy(tmp->context, p->context, sizeof(tmp->context)-1);
730 if (strlen(p->exten))
731 strncpy(tmp->exten, p->exten, sizeof(tmp->exten)-1);
732 if (strlen(language))
733 strncpy(tmp->language, language, sizeof(tmp->language)-1);
735 ast_setstate(tmp, state);
736 ast_mutex_lock(&usecnt_lock);
738 ast_mutex_unlock(&usecnt_lock);
739 ast_update_use_count();
740 if (state != AST_STATE_DOWN) {
741 if (ast_pbx_start(tmp)) {
742 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
751 static struct ast_channel *oss_request(const char *type, int format, void *data, int *cause)
753 int oldformat = format;
754 struct ast_channel *tmp;
755 format &= AST_FORMAT_SLINEAR;
757 ast_log(LOG_NOTICE, "Asked to get a channel of format '%d'\n", oldformat);
761 ast_log(LOG_NOTICE, "Already have a call on the OSS channel\n");
762 *cause = AST_CAUSE_BUSY;
765 tmp= oss_new(&oss, AST_STATE_DOWN);
767 ast_log(LOG_WARNING, "Unable to create new OSS channel\n");
772 static int console_autoanswer(int fd, int argc, char *argv[])
774 if ((argc != 1) && (argc != 2))
775 return RESULT_SHOWUSAGE;
777 ast_cli(fd, "Auto answer is %s.\n", autoanswer ? "on" : "off");
778 return RESULT_SUCCESS;
780 if (!strcasecmp(argv[1], "on"))
782 else if (!strcasecmp(argv[1], "off"))
785 return RESULT_SHOWUSAGE;
787 return RESULT_SUCCESS;
790 static char *autoanswer_complete(char *line, char *word, int pos, int state)
793 #define MIN(a,b) ((a) < (b) ? (a) : (b))
797 if (strlen(word) && !strncasecmp(word, "on", MIN(strlen(word), 2)))
800 if (strlen(word) && !strncasecmp(word, "off", MIN(strlen(word), 3)))
801 return strdup("off");
808 static char autoanswer_usage[] =
809 "Usage: autoanswer [on|off]\n"
810 " Enables or disables autoanswer feature. If used without\n"
811 " argument, displays the current on/off status of autoanswer.\n"
812 " The default value of autoanswer is in 'oss.conf'.\n";
814 static int console_answer(int fd, int argc, char *argv[])
816 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
818 return RESULT_SHOWUSAGE;
820 ast_cli(fd, "No one is calling us\n");
821 return RESULT_FAILURE;
825 ast_queue_frame(oss.owner, &f);
827 return RESULT_SUCCESS;
830 static char sendtext_usage[] =
831 "Usage: send text <message>\n"
832 " Sends a text message for display on the remote terminal.\n";
834 static int console_sendtext(int fd, int argc, char *argv[])
837 char text2send[256] = "";
838 struct ast_frame f = { 0, };
840 return RESULT_SHOWUSAGE;
842 ast_cli(fd, "No one is calling us\n");
843 return RESULT_FAILURE;
845 if (strlen(text2send))
846 ast_cli(fd, "Warning: message already waiting to be sent, overwriting\n");
848 while(tmparg < argc) {
849 strncat(text2send, argv[tmparg++], sizeof(text2send) - strlen(text2send) - 1);
850 strncat(text2send, " ", sizeof(text2send) - strlen(text2send) - 1);
852 if (strlen(text2send)) {
853 f.frametype = AST_FRAME_TEXT;
856 f.datalen = strlen(text2send);
857 ast_queue_frame(oss.owner, &f);
859 return RESULT_SUCCESS;
862 static char answer_usage[] =
864 " Answers an incoming call on the console (OSS) channel.\n";
866 static int console_hangup(int fd, int argc, char *argv[])
869 return RESULT_SHOWUSAGE;
871 if (!oss.owner && !hookstate) {
872 ast_cli(fd, "No call to hangup up\n");
873 return RESULT_FAILURE;
877 ast_queue_hangup(oss.owner);
879 return RESULT_SUCCESS;
882 static int console_flash(int fd, int argc, char *argv[])
884 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH };
886 return RESULT_SHOWUSAGE;
889 ast_cli(fd, "No call to flash\n");
890 return RESULT_FAILURE;
894 ast_queue_frame(oss.owner, &f);
896 return RESULT_SUCCESS;
899 static char hangup_usage[] =
901 " Hangs up any call currently placed on the console.\n";
904 static char flash_usage[] =
906 " Flashes the call currently placed on the console.\n";
908 static int console_dial(int fd, int argc, char *argv[])
910 char tmp[256], *tmp2;
913 struct ast_frame f = { AST_FRAME_DTMF, 0 };
914 if ((argc != 1) && (argc != 2))
915 return RESULT_SHOWUSAGE;
918 for (x=0;x<strlen(argv[1]);x++) {
919 f.subclass = argv[1][x];
920 ast_queue_frame(oss.owner, &f);
923 ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n");
924 return RESULT_FAILURE;
926 return RESULT_SUCCESS;
932 strncpy(tmp, argv[1], sizeof(tmp)-1);
934 strsep(&stringp, "@");
935 tmp2 = strsep(&stringp, "@");
938 if (tmp2 && strlen(tmp2))
941 if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
942 strncpy(oss.exten, mye, sizeof(oss.exten)-1);
943 strncpy(oss.context, myc, sizeof(oss.context)-1);
945 oss_new(&oss, AST_STATE_RINGING);
947 ast_cli(fd, "No such extension '%s' in context '%s'\n", mye, myc);
948 return RESULT_SUCCESS;
951 static char dial_usage[] =
952 "Usage: dial [extension[@context]]\n"
953 " Dials a given extensison (and context if specified)\n";
955 static int console_transfer(int fd, int argc, char *argv[])
960 return RESULT_SHOWUSAGE;
961 if (oss.owner && ast_bridged_channel(oss.owner)) {
962 strncpy(tmp, argv[1], sizeof(tmp) - 1);
963 context = strchr(tmp, '@');
968 context = oss.owner->context;
969 if (ast_exists_extension(ast_bridged_channel(oss.owner), context, tmp, 1, ast_bridged_channel(oss.owner)->cid.cid_num)) {
970 ast_cli(fd, "Whee, transferring %s to %s@%s.\n",
971 ast_bridged_channel(oss.owner)->name, tmp, context);
972 if (ast_async_goto(ast_bridged_channel(oss.owner), context, tmp, 1))
973 ast_cli(fd, "Failed to transfer :(\n");
975 ast_cli(fd, "No such extension exists\n");
978 ast_cli(fd, "There is no call to transfer\n");
980 return RESULT_SUCCESS;
983 static char transfer_usage[] =
984 "Usage: transfer <extension>[@context]\n"
985 " Transfers the currently connected call to the given extension (and\n"
986 "context if specified)\n";
988 static struct ast_cli_entry myclis[] = {
989 { { "answer", NULL }, console_answer, "Answer an incoming console call", answer_usage },
990 { { "hangup", NULL }, console_hangup, "Hangup a call on the console", hangup_usage },
991 { { "flash", NULL }, console_flash, "Flash a call on the console", flash_usage },
992 { { "dial", NULL }, console_dial, "Dial an extension on the console", dial_usage },
993 { { "transfer", NULL }, console_transfer, "Transfer a call to a different extension", transfer_usage },
994 { { "send", "text", NULL }, console_sendtext, "Send text to the remote device", sendtext_usage },
995 { { "autoanswer", NULL }, console_autoanswer, "Sets/displays autoanswer", autoanswer_usage, autoanswer_complete }
1002 struct ast_config *cfg;
1003 struct ast_variable *v;
1006 ast_log(LOG_ERROR, "Unable to create pipe\n");
1009 res = soundcard_init();
1011 if (option_verbose > 1) {
1012 ast_verbose(VERBOSE_PREFIX_2 "No sound card detected -- console channel will be unavailable\n");
1013 ast_verbose(VERBOSE_PREFIX_2 "Turn off OSS support by adding 'noload=chan_oss.so' in /etc/asterisk/modules.conf\n");
1018 ast_log(LOG_WARNING, "XXX I don't work right with non-full duplex sound cards XXX\n");
1019 res = ast_channel_register(type, tdesc, AST_FORMAT_SLINEAR, oss_request);
1021 ast_log(LOG_ERROR, "Unable to register channel class '%s'\n", type);
1024 for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
1025 ast_cli_register(myclis + x);
1026 if ((cfg = ast_load(config))) {
1027 v = ast_variable_browse(cfg, "general");
1029 if (!strcasecmp(v->name, "autoanswer"))
1030 autoanswer = ast_true(v->value);
1031 else if (!strcasecmp(v->name, "silencesuppression"))
1032 silencesuppression = ast_true(v->value);
1033 else if (!strcasecmp(v->name, "silencethreshold"))
1034 silencethreshold = atoi(v->value);
1035 else if (!strcasecmp(v->name, "context"))
1036 strncpy(context, v->value, sizeof(context)-1);
1037 else if (!strcasecmp(v->name, "language"))
1038 strncpy(language, v->value, sizeof(language)-1);
1039 else if (!strcasecmp(v->name, "extension"))
1040 strncpy(exten, v->value, sizeof(exten)-1);
1045 ast_pthread_create(&sthread, NULL, sound_thread, NULL);
1054 for (x=0;x<sizeof(myclis)/sizeof(struct ast_cli_entry); x++)
1055 ast_cli_unregister(myclis + x);
1057 if (sndcmd[0] > 0) {
1062 ast_softhangup(oss.owner, AST_SOFTHANGUP_APPUNLOAD);
1076 ast_mutex_lock(&usecnt_lock);
1078 ast_mutex_unlock(&usecnt_lock);
1084 return ASTERISK_GPL_KEY;