1 diff -Nru asterisk-addons-1.4.6.org/build_tools/menuselect-deps.in asterisk-addons-1.4.6/build_tools/menuselect-deps.in
2 --- asterisk-addons-1.4.6.org/build_tools/menuselect-deps.in 2007-05-14 18:22:44.000000000 +0200
3 +++ asterisk-addons-1.4.6/build_tools/menuselect-deps.in 2008-03-06 08:38:14.000000000 +0100
5 +BLUETOOTH=@PBX_BLUETOOTH@
6 MYSQLCLIENT=@PBX_MYSQLCLIENT@
7 ASTERISK=@PBX_ASTERISK@
8 diff -Nru asterisk-addons-1.4.6.org/channels/chan_mobile.c asterisk-addons-1.4.6/channels/chan_mobile.c
9 --- asterisk-addons-1.4.6.org/channels/chan_mobile.c 1970-01-01 01:00:00.000000000 +0100
10 +++ asterisk-addons-1.4.6/channels/chan_mobile.c 2008-03-06 08:38:57.000000000 +0100
13 + * Asterisk -- An open source telephony toolkit.
15 + * Copyright (C) 1999 - 2006, Digium, Inc.
17 + * Mark Spencer <markster@digium.com>
19 + * See http://www.asterisk.org for more information about
20 + * the Asterisk project. Please do not directly contact
21 + * any of the maintainers of this project for assistance;
22 + * the project provides a web site, mailing lists and IRC
23 + * channels for your use.
25 + * This program is free software, distributed under the terms of
26 + * the GNU General Public License Version 2. See the LICENSE file
27 + * at the top of the source tree.
32 + * \brief Bluetooth Mobile Device channel driver
34 + * \author Dave Bowerman <david.bowerman@gmail.com>
36 + * \ingroup channel_drivers
40 + <depend>bluetooth</depend>
43 +#include <asterisk.h>
45 +ASTERISK_FILE_VERSION(__FILE__, "$Revision: 416 $")
49 +#include <sys/socket.h>
50 +#include <sys/time.h>
54 +#include <arpa/inet.h>
56 +#include <sys/ioctl.h>
59 +#include <bluetooth/bluetooth.h>
60 +#include <bluetooth/hci.h>
61 +#include <bluetooth/hci_lib.h>
62 +#include <bluetooth/sdp.h>
63 +#include <bluetooth/sdp_lib.h>
64 +#include <bluetooth/rfcomm.h>
65 +#include <bluetooth/sco.h>
67 +#include <asterisk/lock.h>
68 +#include <asterisk/channel.h>
69 +#include <asterisk/config.h>
70 +#include <asterisk/logger.h>
71 +#include <asterisk/module.h>
72 +#include <asterisk/pbx.h>
73 +#include <asterisk/options.h>
74 +#include <asterisk/utils.h>
75 +#include <asterisk/linkedlists.h>
76 +#include <asterisk/cli.h>
77 +#include <asterisk/devicestate.h>
78 +#include <asterisk/causes.h>
79 +#include <asterisk/dsp.h>
82 +#define ast_debug(level, ...) do { \
83 + if (option_debug >= (level)) { \
84 + ast_log(LOG_DEBUG, __VA_ARGS__); \
89 +#define AST_MODULE "chan_mobile"
91 +#define MBL_CONFIG "mobile.conf"
93 +static int prefformat = AST_FORMAT_SLINEAR;
95 +static int discovery_interval = 60; /* The device discovery interval, default 60 seconds. */
96 +static int sco_socket; /* This is global so it can be closed on module unload outside of the listener thread */
97 +static sdp_session_t *sdp_session;
105 + MBL_STATE_INIT = 0,
116 + MBL_STATE_OUTGOING,
120 + MBL_STATE_INCOMING,
129 + struct ast_channel *owner; /* Channel we belong to, possibly NULL */
130 + struct ast_frame fr; /* "null" frame */
131 + enum mbl_type type; /* Phone or Headset */
132 + char id[31]; /* The id from mobile.conf */
133 + char bdaddr[18]; /* the bdaddr of the device */
134 + char context[AST_MAX_CONTEXT]; /* the context for incoming calls */
135 + char connected; /* is it connected? */
136 + int rfcomm_port; /* rfcomm port number */
137 + int rfcomm_socket; /* rfcomm socket descriptor */
138 + char rfcomm_buf[256];
139 + int sco_socket; /* sco socket descriptor */
140 + enum mbl_state state; /* monitor thread current state */
141 + pthread_t monitor_thread; /* monitor thread handle */
142 + char sco_in_buf[48 + AST_FRIENDLY_OFFSET];
143 + char sco_out_buf[352];
146 + char dial_number[AST_MAX_EXTENSION]; /* number for the monitor thread to dial */
148 + char ciev_call_0[4]; /* dynamically build reponse strings */
149 + char ciev_call_1[4];
150 + char ciev_callsetup_0[4];
151 + char ciev_callsetup_1[4];
152 + char ciev_callsetup_2[4];
153 + char ciev_callsetup_3[4];
157 + struct ast_dsp *dsp;
158 + struct ast_frame *dsp_fr;
163 + AST_LIST_ENTRY(mbl_pvt) entry;
166 +static AST_LIST_HEAD_STATIC(devices, mbl_pvt);
168 +/* The discovery thread */
169 +static pthread_t discovery_thread = AST_PTHREADT_NULL;
170 +/* The sco listener thread */
171 +static pthread_t sco_listener_thread = AST_PTHREADT_NULL;
174 +static const char show_usage[] =
175 +"Usage: mobile show devices\n"
176 +" Shows the state of Bluetooth Cell / Mobile devices.\n";
178 +static const char search_usage[] =
179 +"Usage: mobile search\n"
180 +" Searches for Bluetooth Cell / Mobile devices in range.\n";
182 +static const char rfcomm_usage[] =
183 +"Usage: mobile rfcomm command\n"
184 +" Send command to the rfcomm port.\n";
186 +static int do_show_devices(int, int, char **);
187 +static int do_search_devices(int, int, char **);
188 +static int do_send_rfcomm(int, int, char **);
190 +static struct ast_cli_entry mbl_cli[] = {
191 + {{"mobile", "show", "devices", NULL}, do_show_devices, "Show Bluetooth Cell / Mobile devices", show_usage},
192 + {{"mobile", "search", NULL}, do_search_devices, "Search for Bluetooth Cell / Mobile devices", search_usage},
193 + {{"mobile", "rfcomm", NULL}, do_send_rfcomm, "Send commands to the rfcomm port for debugging", rfcomm_usage}
197 +static char *app_mblstatus = "MobileStatus";
198 +static char *mblstatus_synopsis = "MobileStatus(Device,Variable)";
199 +static char *mblstatus_desc =
200 +"MobileStatus(Device,Variable)\n"
201 +" Device - Id of mobile device from mobile.conf\n"
202 +" Variable - Variable to store status in will be 1-3.\n"
203 +" In order, Disconnected, Connected & Free, Connected & Busy.\n";
205 +static char *app_mblsendsms = "MobileSendSMS";
206 +static char *mblsendsms_synopsis = "MobileSendSMS(Device,Dest,Message)";
207 +static char *mblsendsms_desc =
208 +"MobileSendSms(Device,Dest,Message)\n"
209 +" Device - Id of device from mobile.conf\n"
210 +" Dest - destination\n"
211 +" Message - text of the message\n";
213 +static struct ast_channel *mbl_request(const char *type, int format, void *data, int *cause);
214 +static int mbl_call(struct ast_channel *ast, char *dest, int timeout);
215 +static int mbl_hangup(struct ast_channel *ast);
216 +static int mbl_answer(struct ast_channel *ast);
217 +static int mbl_digit_begin(struct ast_channel *ast, char digit);
218 +static int mbl_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
219 +static struct ast_frame *mbl_read(struct ast_channel *ast);
220 +static int mbl_write(struct ast_channel *ast, struct ast_frame *frame);
221 +static int mbl_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
222 +static int mbl_devicestate(void *data);
223 +static struct ast_channel *mbl_new(int state, struct mbl_pvt *pvt, char *cid_num);
225 +static int rfcomm_write(struct mbl_pvt *pvt, char *buf);
226 +static int rfcomm_read(struct mbl_pvt *pvt, char *buf, char flush, int timeout);
227 +static int sco_connect(char *bdaddr);
228 +static int sdp_search(char *addr, int profile);
230 +static const struct ast_channel_tech mbl_tech = {
232 + .description = "Bluetooth Mobile Device Channel Driver",
233 + .capabilities = AST_FORMAT_SLINEAR,
234 + .requester = mbl_request,
236 + .hangup = mbl_hangup,
237 + .answer = mbl_answer,
238 + .send_digit_begin = mbl_digit_begin,
239 + .send_digit_end = mbl_digit_end,
241 + .write = mbl_write,
242 + .fixup = mbl_fixup,
243 + .devicestate = mbl_devicestate
246 +static int do_show_devices(int fd, int argc, char **argv)
249 + struct mbl_pvt *pvt;
251 + #define FORMAT "%-15.15s %-17.17s %-9.9s %-5.5s %-3.3s\n"
253 + ast_cli(fd, FORMAT, "ID", "Address", "Connected", "State", "SMS");
254 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
255 + ast_cli(fd, FORMAT, pvt->id, pvt->bdaddr, pvt->connected?"Yes":"No", (pvt->state == MBL_STATE_IDLE)?"Free":(pvt->state < MBL_STATE_IDLE)?"Init":"Busy", (pvt->has_sms)?"Yes":"No");
258 + return RESULT_SUCCESS;
262 +static int do_search_devices(int fd, int argc, char **argv)
266 + inquiry_info *ii = NULL;
267 + int max_rsp, num_rsp;
268 + int dev_id, len, flags;
269 + int i, phport, hsport;
270 + char addr[19] = {0};
271 + char name[31] = {0};
273 + #define FORMAT2 "%-17.17s %-30.30s %-6.6s %-7.7s %-4.4s\n"
274 + #define FORMAT3 "%-17.17s %-30.30s %-6.6s %-7.7s %d\n"
276 + dev_id = hci_get_route(NULL);
277 + hci_socket = hci_open_dev(dev_id);
280 + flags = IREQ_CACHE_FLUSH;
282 + ii = (inquiry_info*)malloc(max_rsp * sizeof(inquiry_info));
283 + num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
285 + ast_cli(fd, FORMAT2, "Address", "Name", "Usable", "Type", "Port");
286 + for (i = 0; i < num_rsp; i++) {
287 + ba2str(&(ii+i)->bdaddr, addr);
289 + if (hci_read_remote_name(hci_socket, &(ii+i)->bdaddr, sizeof(name)-1, name, 0) < 0)
290 + strcpy(name, "[unknown]");
291 + phport = sdp_search(addr, HANDSFREE_AGW_PROFILE_ID);
293 + hsport = sdp_search(addr, HEADSET_PROFILE_ID);
296 + ast_cli(fd, FORMAT3, addr, name, (phport > 0 || hsport > 0)?"Yes":"No", (phport > 0)?"Phone":"Headset", (phport > 0)?phport:hsport);
299 + ast_cli(fd, "No Bluetooth Cell / Mobile devices found.\n");
303 + hci_close_dev(hci_socket);
305 + return RESULT_SUCCESS;
309 +static int do_send_rfcomm(int fd, int argc, char **argv)
312 + struct mbl_pvt *pvt;
315 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
316 + if (!strcmp(pvt->id, argv[2]))
320 + if (!pvt || !pvt->connected) {
321 + sprintf(buf, "Device %s not found.\n", argv[2]);
323 + return RESULT_SUCCESS;
326 + sprintf(buf, "%s\r", argv[3]);
327 + rfcomm_write(pvt, buf);
329 + return RESULT_SUCCESS;
333 +static int mbl_status_exec(struct ast_channel *ast, void *data)
336 + struct mbl_pvt *pvt;
337 + char *args = NULL, *device = NULL, *variable = NULL;
344 + args = ast_strdupa((char *)data);
345 + device = strsep(&args, "|");
346 + if (device && (device[0] != 0x00)) {
353 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
354 + if (!strcmp(pvt->id, device))
359 + if (pvt->connected)
365 + sprintf(status, "%d", stat);
366 + pbx_builtin_setvar_helper(ast, variable, status);
372 +static int mbl_sendsms_exec(struct ast_channel *ast, void *data)
375 + struct mbl_pvt *pvt;
376 + char *args = NULL, *device = NULL, *dest = NULL, *message = NULL;
381 + args = ast_strdupa((char *)data);
382 + device = strsep(&args, "|");
383 + if (device && (device[0] != 0x00)) {
384 + dest = strsep(&args, "|");
385 + if (dest && (dest[0] != 0x00)) {
387 + if (!message || (message[0] == 0x00)) {
388 + ast_log(LOG_ERROR,"NULL Message to be sent-- SMS will not be sent.\n");
392 + ast_log(LOG_ERROR,"NULL destination for message -- SMS will not be sent.\n");
397 + ast_log(LOG_ERROR,"NULL device for message -- SMS will not be sent.\n");
402 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
403 + if (!strcmp(pvt->id, device))
408 + ast_log(LOG_ERROR,"Bluetooth device %s wasn't found in the list -- SMS will not be sent.\n",device);
412 + if (!pvt->connected) {
413 + ast_log(LOG_ERROR,"bluetooth device %s wasn't connected -- SMS will not be sent.\n",device);
417 + if (!pvt->has_sms) {
418 + ast_log(LOG_ERROR,"bluetooth device %s doesn't handle SMS -- SMS will not be sent.\n",device);
422 + if (pvt->state != MBL_STATE_IDLE) {
423 + ast_log(LOG_ERROR,"bluetooth device %s isn't IDLE -- SMS will not be sent.\n",device);
427 + strcpy(pvt->dial_number, dest);
428 + memset(pvt->sms_txt, 0x0, sizeof(pvt->sms_txt));
429 + strncpy(pvt->sms_txt, message, 160);
430 + pvt->state = MBL_STATE_OUTSMS;
436 +static struct ast_channel *mbl_request(const char *type, int format, void *data, int *cause)
439 + struct ast_channel *chn = NULL;
440 + struct mbl_pvt *pvt;
441 + char *dest_dev = NULL;
442 + char *dest_num = NULL;
446 + ast_log(LOG_WARNING, "Channel requested with no data\n");
447 + *cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
451 + oldformat = format;
452 + format &= (AST_FORMAT_SLINEAR);
454 + ast_log(LOG_WARNING, "Asked to get a channel of unsupported format '%d'\n", oldformat);
455 + *cause = AST_CAUSE_FACILITY_NOT_IMPLEMENTED;
459 + dest_dev = ast_strdupa((char *)data);
461 + dest_num = strchr(dest_dev, '/');
463 + *dest_num++ = 0x00;
465 + /* Find requested device and make sure its connected. */
466 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
467 + if (!strcmp(pvt->id, dest_dev)) {
471 + if (!pvt || !pvt->connected || pvt->owner) {
472 + ast_log(LOG_WARNING, "Request to call on device %s which is not connected / already in use.\n", dest_dev);
473 + *cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
477 + if ((pvt->type == MBL_TYPE_PHONE) && !dest_num) {
478 + ast_log(LOG_WARNING, "Cant determine destination number.\n");
479 + *cause = AST_CAUSE_INCOMPATIBLE_DESTINATION;
483 + pvt->sco_out_ptr = pvt->sco_out_buf;
484 + pvt->sco_out_len = 0;
486 + chn = mbl_new(AST_STATE_DOWN, pvt, NULL);
488 + ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
489 + *cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
497 +static int mbl_call(struct ast_channel *ast, char *dest, int timeout)
500 + struct mbl_pvt *pvt;
501 + char *dest_dev = NULL;
502 + char *dest_num = NULL;
504 + dest_dev = ast_strdupa((char *)dest);
506 + pvt = ast->tech_pvt;
508 + if (pvt->type == MBL_TYPE_PHONE) {
509 + dest_num = strchr(dest_dev, '/');
511 + ast_log(LOG_WARNING, "Cant determine destination number.\n");
514 + *dest_num++ = 0x00;
517 + if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
518 + ast_log(LOG_WARNING, "mbl_call called on %s, neither down nor reserved\n", ast->name);
522 + ast_debug(1, "Calling %s on %s\n", dest, ast->name);
524 + if (pvt->type == MBL_TYPE_PHONE) {
525 + ast_copy_string(pvt->dial_number, dest_num, sizeof(pvt->dial_number));
526 + pvt->state = MBL_STATE_DIAL;
527 + pvt->dial_timeout = (timeout == 0) ? 30 : timeout;
529 + pvt->state = MBL_STATE_RING;
537 +static int mbl_hangup(struct ast_channel *ast)
540 + struct mbl_pvt *pvt;
542 + if (!ast->tech_pvt) {
543 + ast_log(LOG_WARNING, "Asked to hangup channel not connected\n");
546 + pvt = ast->tech_pvt;
548 + ast_debug(1, "Hanging up device %s.\n", pvt->id);
550 + ast_channel_lock(ast);
552 + ast_channel_unlock(ast);
554 + if (pvt->type == MBL_TYPE_HEADSET && pvt->sco_socket != -1) {
555 + close(pvt->sco_socket);
556 + pvt->sco_socket = -1;
559 + if ((pvt->state == MBL_STATE_INCOMING || pvt->state == MBL_STATE_OUTGOING || pvt->state == MBL_STATE_DIAL1 || pvt->state == MBL_STATE_RING3) && pvt->type == MBL_TYPE_PHONE) {
560 + rfcomm_write(pvt, "AT+CHUP\r");
561 + pvt->state = MBL_STATE_HANGUP;
562 + pvt->hangup_count = 0;
564 + pvt->state = MBL_STATE_IDLE;
567 + ast->tech_pvt = NULL;
568 + ast_setstate(ast, AST_STATE_DOWN);
574 +static int mbl_answer(struct ast_channel *ast)
577 + struct mbl_pvt *pvt;
579 + pvt = ast->tech_pvt;
581 + rfcomm_write(pvt, "ATA\r");
583 + ast_setstate(ast, AST_STATE_UP);
585 + pvt->sent_answer = 1;
591 +static int mbl_digit_begin(struct ast_channel *chan, char digit)
598 +static int mbl_digit_end(struct ast_channel *ast, char digit, unsigned int duration)
601 + struct mbl_pvt *pvt;
604 + pvt = ast->tech_pvt;
606 + if (pvt->type == MBL_TYPE_HEADSET)
609 + ast_debug(1, "Dialed %c\n", digit);
624 + sprintf(buf, "AT+VTS=%c\r", digit);
625 + rfcomm_write(pvt, buf);
628 + ast_log(LOG_WARNING, "Unknown digit '%c'\n", digit);
638 + The SCO protocol basically delivers audio in 48 byte 'frames' in slin format.
639 + Here we just package these into an ast_frame and return them.
640 + The SCO connection from the device to Asterisk happens asynchronously, so it is feasible
641 + that Asterisk will call mbl_read() before the device has connected. In that case we just return
646 +static struct ast_frame *mbl_read(struct ast_channel *ast)
649 + struct mbl_pvt *pvt = ast->tech_pvt;
651 + struct ast_frame *f;
654 + return &ast_null_frame;
657 + if (pvt->state == MBL_STATE_HANGUP) {
658 + return &ast_null_frame;
661 + if (pvt->sco_socket == -1) {
662 + return &ast_null_frame;
665 + pvt->fr.frametype = AST_FRAME_VOICE;
666 + pvt->fr.subclass = AST_FORMAT_SLINEAR;
667 + pvt->fr.data = pvt->sco_in_buf + AST_FRIENDLY_OFFSET;
669 + if ((r = read(pvt->sco_socket, pvt->fr.data, 48)) == 48) {
670 + if (pvt->skip_frames == 0) {
671 + f = ast_dsp_process(0, pvt->dsp, &pvt->fr);
672 + if (f && (f->frametype == AST_FRAME_DTMF_END)) {
673 + pvt->fr.frametype = AST_FRAME_DTMF_END;
674 + pvt->fr.subclass = f->subclass;
675 + pvt->skip_frames = pvt->dtmf_skip;
679 + pvt->skip_frames--;
681 + } else if (r == -1) {
682 + ast_debug(1, "mbl_read() read error %d.\n", errno);
683 + close(pvt->sco_socket);
684 + pvt->sco_socket = -1;
685 + ast_channel_lock(ast);
687 + ast_channel_unlock(ast);
689 + ast_debug(1, "mbl_read() read short frame. (%d)\n", r);
692 + return &ast_null_frame;
698 + We need to deliver 48 byte 'frames' of slin format audio to the device.
699 + mbl_write() handles this by buffering short frames until the next time we are called.
703 +static int mbl_write(struct ast_channel *ast, struct ast_frame *frame)
706 + struct mbl_pvt *pvt = ast->tech_pvt;
707 + int num_frames, i, r;
710 + if (frame->frametype != AST_FRAME_VOICE) {
713 + if (pvt->sco_socket == -1) {
717 + if (pvt->state == MBL_STATE_HANGUP) {
721 + if (frame->datalen > sizeof(pvt->sco_out_buf) - pvt->sco_out_len) {
722 + frame->datalen = sizeof(pvt->sco_out_buf) - pvt->sco_out_len;
723 + ast_debug(1, "Overrun on sco_out_buf detected.\n");
726 + memmove(pvt->sco_out_ptr, frame->data, frame->datalen);
727 + pvt->sco_out_len += frame->datalen;
728 + num_frames = pvt->sco_out_len / 48;
730 + pfr = pvt->sco_out_buf;
731 + for (i=0; i<num_frames; i++) {
732 + if ((r = write(pvt->sco_socket, pfr, 48)) == -1) {
733 + close(pvt->sco_socket);
734 + pvt->sco_socket = -1;
739 + pvt->sco_out_len = pvt->sco_out_len - (num_frames * 48);
740 + memmove(pvt->sco_out_buf, pfr, pvt->sco_out_len);
741 + pvt->sco_out_ptr = pvt->sco_out_buf + pvt->sco_out_len;
747 +static int mbl_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
750 + struct mbl_pvt *pvt = oldchan->tech_pvt;
752 + if (pvt && pvt->owner == oldchan)
753 + pvt->owner = newchan;
759 +static int mbl_devicestate(void *data)
763 + int res = AST_DEVICE_INVALID;
764 + struct mbl_pvt *pvt;
766 + device = ast_strdupa(S_OR(data, ""));
768 + ast_debug(1, "Checking device state for device %s\n", device);
770 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
771 + if (!strcmp(pvt->id, device))
776 + if (pvt->connected) {
778 + res = AST_DEVICE_INUSE;
780 + res = AST_DEVICE_NOT_INUSE;
788 +static struct ast_channel *mbl_new(int state, struct mbl_pvt *pvt, char *cid_num)
791 + struct ast_channel *chn;
793 + chn = ast_channel_alloc(1, state, 0, 0, 0, 0, 0, 0, "Mobile/%s-%04lx", pvt->id, ast_random() & 0xffff);
795 + chn->tech = &mbl_tech;
796 + chn->nativeformats = prefformat;
797 + chn->rawreadformat = prefformat;
798 + chn->rawwriteformat = prefformat;
799 + chn->writeformat = prefformat;
800 + chn->readformat = prefformat;
801 + chn->readq.first = NULL;
802 + pvt->fr.frametype = AST_FRAME_VOICE;
803 + pvt->fr.subclass = AST_FORMAT_SLINEAR;
804 + pvt->fr.datalen = 48;
805 + pvt->fr.samples = 24;
806 + pvt->fr.src = "Mobile";
807 + pvt->fr.offset = AST_FRIENDLY_OFFSET;
808 + pvt->fr.mallocd = 0;
809 + pvt->fr.delivery.tv_sec = 0;
810 + pvt->fr.delivery.tv_usec = 0;
811 + pvt->fr.data = pvt->sco_in_buf + AST_FRIENDLY_OFFSET;
812 + chn->tech_pvt = pvt;
813 + if (state == AST_STATE_RING)
815 + ast_copy_string(chn->context, pvt->context, sizeof(chn->context));
816 + ast_copy_string(chn->exten, "s", sizeof(chn->exten));
817 + ast_string_field_set(chn, language, "en");
819 + chn->cid.cid_num = ast_strdup(cid_num);
820 + chn->cid.cid_name = ast_strdup(pvt->id);
829 +static int rfcomm_connect(char *bdaddr, int remote_channel) {
832 + struct sockaddr_rc addr;
835 + str2ba(bdaddr, &dst);
837 + if ((s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0) {
838 + ast_debug(1, "socket() failed (%d).\n", errno);
842 + memset(&addr, 0, sizeof(addr));
843 + addr.rc_family = AF_BLUETOOTH;
844 + bacpy(&addr.rc_bdaddr, &dst);
845 + addr.rc_channel = remote_channel;
846 + if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
847 + ast_debug(1, "connect() failed (%d).\n", errno);
856 +static int rfcomm_write(struct mbl_pvt *pvt, char *buf)
863 + ast_debug(1, "rfcomm_write() (%s) [%s]\n", pvt->id, buf);
867 + if ((num_write = write(pvt->rfcomm_socket, p, len)) == -1) {
868 + ast_debug(1, "rfcomm_write() error [%d]\n", errno);
881 + Here we need to return complete '\r' terminated single responses to the devices monitor thread, or
882 + a timeout if nothing is available.
883 + The rfcomm connection to the device is asynchronous, so there is no guarantee that responses will
884 + be returned in a single read() call. We handle this by buffering the input and returning one response
885 + per call, or a timeout if nothing is available.
889 +static int rfcomm_read(struct mbl_pvt *pvt, char *buf, char flush, int timeout)
892 + int sel, rlen, slen;
898 + if ((p = strchr(pvt->rfcomm_buf, '\r'))) {
902 + memmove(buf, pvt->rfcomm_buf, strlen(pvt->rfcomm_buf));
903 + *(buf + strlen(pvt->rfcomm_buf)) = 0x00;
904 + memmove(pvt->rfcomm_buf, p, strlen(p));
905 + *(pvt->rfcomm_buf+strlen(p)) = 0x00;
909 + pvt->rfcomm_buf[0] = 0x00;
913 + FD_SET(pvt->rfcomm_socket, &rfds);
915 + tv.tv_sec = timeout;
918 + if ((sel = select(pvt->rfcomm_socket + 1, &rfds, NULL, NULL, &tv)) > 0) {
919 + if (FD_ISSET(pvt->rfcomm_socket, &rfds)) {
920 + slen = strlen(pvt->rfcomm_buf);
921 + rlen = read(pvt->rfcomm_socket, pvt->rfcomm_buf + slen, sizeof(pvt->rfcomm_buf) - slen - 1);
923 + pvt->rfcomm_buf[slen+rlen] = 0x00;
924 + if ((p = strchr(pvt->rfcomm_buf, '\r'))) {
928 + memmove(buf, pvt->rfcomm_buf, strlen(pvt->rfcomm_buf));
929 + *(buf + strlen(pvt->rfcomm_buf)) = 0x00;
930 + memmove(pvt->rfcomm_buf, p, strlen(p));
931 + *(pvt->rfcomm_buf+strlen(p)) = 0x00;
937 + } else if (sel == 0) { /* timeout */
945 +static int sco_connect(char *bdaddr)
949 + struct sockaddr_sco addr;
952 + str2ba(bdaddr, &dst);
954 + if ((s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)) < 0) {
955 + ast_debug(1, "socket() failed (%d).\n", errno);
959 + memset(&addr, 0, sizeof(addr));
960 + addr.sco_family = AF_BLUETOOTH;
961 + bacpy(&addr.sco_bdaddr, &dst);
963 + if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
964 + ast_debug(1, "sco connect() failed (%d).\n", errno);
975 + sdp_search() performs a service discovery on the given device to determine whether
976 + or not it supports the Handsfree Profile.
980 +static int sdp_search(char *addr, int profile)
983 + sdp_session_t *session = 0;
986 + uint32_t range = 0x0000ffff;
987 + sdp_list_t *response_list, *search_list, *attrid_list;
989 + sdp_list_t *proto_list;
990 + sdp_record_t *sdprec;
992 + str2ba(addr, &bdaddr);
994 + session = sdp_connect(BDADDR_ANY, &bdaddr, SDP_RETRY_IF_BUSY);
996 + ast_debug(1, "sdp_connect() failed on device %s.\n", addr);
1000 + sdp_uuid32_create(&svc_uuid, profile);
1001 + search_list = sdp_list_append(0, &svc_uuid);
1002 + attrid_list = sdp_list_append(0, &range);
1003 + response_list = 0x00;
1004 + status = sdp_service_search_attr_req(session, search_list, SDP_ATTR_REQ_RANGE, attrid_list, &response_list);
1005 + if (status == 0) {
1006 + if (response_list) {
1007 + sdprec = (sdp_record_t *) response_list->data;
1008 + proto_list = 0x00;
1009 + if (sdp_get_access_protos(sdprec, &proto_list) == 0) {
1010 + port = sdp_get_proto_port(proto_list, RFCOMM_UUID);
1011 + sdp_list_free(proto_list, 0);
1013 + sdp_record_free(sdprec);
1014 + sdp_list_free(response_list, 0);
1016 + ast_debug(1, "No responses returned for device %s.\n", addr);
1018 + ast_debug(1, "sdp_service_search_attr_req() failed on device %s.\n", addr);
1021 + sdp_list_free(search_list, 0);
1022 + sdp_list_free(attrid_list, 0);
1023 + sdp_close(session);
1033 + Register GENERIC_AUDIO & HEADSET with the SDP daemon on the Asterisk Box.
1034 + This assists connections to phones/pda's with dud bluetooth stacks like the IMate Jasjam
1039 +static sdp_session_t *sdp_register(void)
1042 + uint32_t service_uuid_int[] = {0, 0, 0, GENERIC_AUDIO_SVCLASS_ID};
1043 + uint8_t rfcomm_channel = 1;
1044 + const char *service_name = "Asterisk PABX";
1045 + const char *service_dsc = "Asterisk PABX";
1046 + const char *service_prov = "Asterisk";
1048 + uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid, svc_class1_uuid, svc_class2_uuid;
1049 + sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *svc_uuid_list = 0;
1050 + sdp_data_t *channel = 0;
1053 + sdp_session_t *session = 0;
1055 + sdp_record_t *record = sdp_record_alloc();
1057 + sdp_uuid128_create(&svc_uuid, &service_uuid_int);
1058 + sdp_set_service_id(record, svc_uuid);
1060 + sdp_uuid32_create(&svc_class1_uuid, GENERIC_AUDIO_SVCLASS_ID);
1061 + sdp_uuid32_create(&svc_class2_uuid, HEADSET_PROFILE_ID);
1063 + svc_uuid_list = sdp_list_append(0, &svc_class1_uuid);
1064 + svc_uuid_list = sdp_list_append(svc_uuid_list, &svc_class2_uuid);
1065 + sdp_set_service_classes(record, svc_uuid_list);
1067 + sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
1068 + root_list = sdp_list_append(0, &root_uuid);
1069 + sdp_set_browse_groups( record, root_list );
1071 + sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID);
1072 + l2cap_list = sdp_list_append(0, &l2cap_uuid);
1073 + proto_list = sdp_list_append(0, l2cap_list);
1075 + sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
1076 + channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel);
1077 + rfcomm_list = sdp_list_append(0, &rfcomm_uuid);
1078 + sdp_list_append(rfcomm_list, channel);
1079 + sdp_list_append(proto_list, rfcomm_list);
1081 + access_proto_list = sdp_list_append(0, proto_list);
1082 + sdp_set_access_protos(record, access_proto_list);
1084 + sdp_set_info_attr(record, service_name, service_prov, service_dsc);
1086 + if (!(session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY)))
1087 + ast_log(LOG_WARNING, "Failed to connect sdp and create session.\n");
1089 + err = sdp_record_register(session, record, 0);
1091 + sdp_data_free(channel);
1092 + sdp_list_free(rfcomm_list, 0);
1093 + sdp_list_free(root_list, 0);
1094 + sdp_list_free(access_proto_list, 0);
1095 + sdp_list_free(svc_uuid_list, 0);
1103 + Phone Monitor Thread
1105 + This thread is spun once a phone device is discovered and considered capable of being used, i.e. supports Handsfree Profile,
1106 + and its configured in mobile.conf.
1107 + The thread lives for the lifetime of the bluetooth connection, and handles the 'control' side of all calls.
1111 +static void *do_monitor_phone(void *data)
1114 + struct mbl_pvt *pvt = (struct mbl_pvt *)data;
1115 + struct ast_channel *chn;
1118 + char cid_num[AST_MAX_EXTENSION], *pcids, *pcide;
1119 + int s, t, i, smsi;
1120 + int group, group2;
1121 + int callp = 0, callsetupp;
1122 + char brsf, nsmode, *p, *p1;
1124 + char sms_txt[161];
1126 + brsf = nsmode = 0;
1128 + if (!rfcomm_write(pvt, "AT+BRSF=4\r"))
1133 + if (pvt->state == MBL_STATE_DIAL1)
1134 + t = pvt->dial_timeout;
1135 + else if (pvt->state == MBL_STATE_HANGUP)
1137 + else if (pvt->state == MBL_STATE_OUTSMS1)
1139 + else if (pvt->state == MBL_STATE_OUTSMS2)
1144 + s = rfcomm_read(pvt, buf, 0, t);
1146 + if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) {
1147 + ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf);
1148 + switch (pvt->state) {
1149 + case MBL_STATE_INIT:
1150 + if (strstr(buf, "+BRSF:")) {
1152 + } else if (strstr(buf, "ERROR") && !nsmode) { /* Hmmm, Non-Standard Phone, just continue */
1153 + rfcomm_write(pvt, "AT+CIND=?\r");
1156 + } else if (strstr(buf, "OK") && brsf) {
1157 + rfcomm_write(pvt, "AT+CIND=?\r");
1161 + case MBL_STATE_INIT1:
1162 + if (strstr(buf, "+CIND:")) {
1163 + group = callp = callsetupp = 0;
1165 + for (i=0; i<strlen(buf); i++) {
1166 + if (buf[i] == '(')
1168 + if (buf[i] == ')') {
1173 + if (strstr(buf+i, "\"call\""))
1175 + if (strstr(buf+i, "\"call_setup\""))
1176 + callsetupp = group2;
1177 + if (strstr(buf+i, "\"callsetup\""))
1178 + callsetupp = group2;
1180 + sprintf(pvt->ciev_call_0, "%d,0", callp);
1181 + sprintf(pvt->ciev_call_1, "%d,1", callp);
1182 + sprintf(pvt->ciev_callsetup_0, "%d,0", callsetupp);
1183 + sprintf(pvt->ciev_callsetup_1, "%d,1", callsetupp);
1184 + sprintf(pvt->ciev_callsetup_2, "%d,2", callsetupp);
1185 + sprintf(pvt->ciev_callsetup_3, "%d,3", callsetupp);
1186 + if (callsetupp == 0) /* This phone has no call setup indication!! ... */
1187 + pvt->no_callsetup = 1;
1188 + ast_debug(1, "CIEV_CALL=%d CIEV_CALLSETUP=%d\n", callp, callsetupp);
1190 + if (strstr(buf, "OK")) {
1191 + rfcomm_write(pvt, "AT+CIND?\r");
1195 + case MBL_STATE_INIT2:
1196 + if ((p = strstr(buf, "+CIND:"))) {
1198 + if (*(p+(callp*2)) == '1') {
1199 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s has a call in progress - delaying connection.\n", pvt->id);
1202 + } else if (strstr(buf, "OK")) {
1203 + rfcomm_write(pvt, "AT+CMER=3,0,0,1\r");
1207 + case MBL_STATE_INIT3:
1208 + if (strstr(buf, "OK")) {
1209 + rfcomm_write(pvt, "AT+CLIP=1\r");
1213 + case MBL_STATE_INIT4:
1214 + if (strstr(buf, "OK")) {
1215 + rfcomm_write(pvt, "AT+CMGF=1\r");
1219 + case MBL_STATE_INIT5:
1220 + if (strstr(buf, "ERROR")) { /* No SMS Support ! */
1221 + pvt->state = MBL_STATE_PREIDLE;
1222 + } else if (strstr(buf, "OK")) {
1223 + rfcomm_write(pvt, "AT+CNMI=2,1,0,1,0\r");
1227 + case MBL_STATE_INIT6:
1228 + if (strstr(buf, "OK")) { /* We have SMS Support */
1230 + pvt->state = MBL_STATE_PREIDLE;
1231 + } else if (strstr(buf, "ERROR")) {
1233 + ast_log(LOG_NOTICE,"Device %s has no bluetooth SMS capability.\n", pvt->id);
1234 + pvt->state = MBL_STATE_PREIDLE;
1237 + case MBL_STATE_PREIDLE: /* Nothing handled here, wait for timeout, then off we go... */
1239 + case MBL_STATE_IDLE:
1240 + ast_debug(1, "Device %s %s [%s]\n", pvt->bdaddr, pvt->id, buf);
1241 + if (strstr(buf, "RING")) {
1242 + pvt->state = MBL_STATE_RING;
1243 + } else if (strstr(buf, "+CIEV:")) {
1244 + if (strstr(buf, pvt->ciev_callsetup_3)) { /* User has dialed out on handset */
1245 + monitor = 0; /* We disconnect now, as he is */
1246 + } /* probably leaving BT range... */
1249 + case MBL_STATE_DIAL: /* Nothing handled here, we need to wait for a timeout */
1251 + case MBL_STATE_DIAL1:
1252 + if (strstr(buf, "OK")) {
1253 + if (pvt->no_callsetup) {
1254 + ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
1256 + ast_setstate(pvt->owner, AST_STATE_RINGING);
1258 + pvt->state = MBL_STATE_OUTGOING;
1261 + case MBL_STATE_OUTGOING:
1262 + if (strstr(buf, "+CIEV")) {
1263 + if (strstr(buf, pvt->ciev_call_0)) { /* call was hung up */
1264 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1265 + } else if (strstr(buf, pvt->ciev_callsetup_3)) { /* b-party ringing */
1266 + ast_queue_control(pvt->owner, AST_CONTROL_RINGING);
1267 + } else if (strstr(buf, pvt->ciev_call_1) && !pvt->no_callsetup) { /* b-party answer */
1268 + ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
1272 + case MBL_STATE_RING:
1273 + cid_num[0] = 0x00;
1274 + if ((pcids = strstr(buf, "+CLIP:"))) {
1275 + if ((pcids = strchr(pcids, '"'))) {
1276 + if ((pcide = strchr(pcids+1, '"'))) {
1277 + strncpy(cid_num, pcids+1, pcide - pcids - 1);
1278 + cid_num[pcide - pcids - 1] = 0x00;
1281 + pvt->sco_out_ptr = pvt->sco_out_buf;
1282 + pvt->sco_out_len = 0;
1283 + pvt->sent_answer = 0;
1284 + chn = mbl_new(AST_STATE_RING, pvt, cid_num);
1286 + if (ast_pbx_start(chn)) {
1287 + ast_log(LOG_ERROR, "Unable to start pbx on incoming call.\n");
1290 + pvt->state = MBL_STATE_RING3;
1292 + ast_log(LOG_ERROR, "Unable to allocate channel for incoming call.\n");
1293 + rfcomm_write(pvt, "AT+CHUP\r");
1294 + pvt->state = MBL_STATE_IDLE;
1298 + case MBL_STATE_RING2:
1299 + pvt->sco_out_ptr = pvt->sco_out_buf;
1300 + pvt->sco_out_len = 0;
1301 + pvt->sent_answer = 0;
1302 + chn = mbl_new(AST_STATE_RING, pvt, cid_num);
1304 + if (ast_pbx_start(chn)) {
1305 + ast_log(LOG_ERROR, "Unable to start pbx on incoming call.\n");
1308 + pvt->state = MBL_STATE_RING3;
1310 + ast_log(LOG_ERROR, "Unable to allocate channel for incoming call.\n");
1311 + rfcomm_write(pvt, "AT+CHUP\r");
1312 + pvt->state = MBL_STATE_IDLE;
1315 + case MBL_STATE_RING3:
1316 + if (strstr(buf, "+CIEV")) {
1317 + if (strstr(buf, pvt->ciev_call_1)) {
1318 + if (pvt->sent_answer) { /* We answered */
1319 + pvt->state = MBL_STATE_INCOMING;
1320 + } else { /* User answered on handset!, disconnect */
1321 + pvt->state = MBL_STATE_IDLE;
1322 + ast_log(LOG_NOTICE,"Closing the sco_socket in RING3 with CIEV\n");
1323 + if (pvt->sco_socket > -1)
1324 + close(pvt->sco_socket);
1325 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1328 + if ((strstr(buf, pvt->ciev_callsetup_0) || strstr(buf, pvt->ciev_call_0))) { /* Caller disconnected */
1329 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1333 + case MBL_STATE_INCOMING:
1334 + if (strstr(buf, "+CIEV")) {
1335 + if (strstr(buf, pvt->ciev_call_0)) {
1336 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1340 + case MBL_STATE_HANGUP:
1341 + if (strstr(buf, "OK") || strstr(buf, pvt->ciev_call_0)) {
1342 + pvt->state = MBL_STATE_IDLE;
1345 + case MBL_STATE_INSMS:
1346 + if (strstr(buf, "+CMGR:")) {
1347 + memset(sms_src, 0x00, sizeof(sms_src));
1348 + if ((p = strchr(buf, ','))) {
1349 + if (*(++p) == '"')
1351 + if ((p1 = strchr(p, ','))) {
1352 + if (*(--p1) == '"')
1354 + memset(sms_src, 0x00, sizeof(sms_src));
1355 + strncpy(sms_src, p, p1 - p + 1);
1358 + } else if (strstr(buf, "OK")) {
1359 + chn = mbl_new(AST_STATE_DOWN, pvt, NULL);
1360 + strcpy(chn->exten, "sms");
1361 + pbx_builtin_setvar_helper(chn, "SMSSRC", sms_src);
1362 + pbx_builtin_setvar_helper(chn, "SMSTXT", sms_txt);
1363 + if (ast_pbx_start(chn))
1364 + ast_log(LOG_ERROR, "Unable to start pbx on incoming sms.\n");
1365 + pvt->state = MBL_STATE_IDLE;
1367 + memset(sms_txt, 0x00, sizeof(sms_txt));
1368 + strncpy(sms_txt, buf, strlen(buf));
1371 + case MBL_STATE_OUTSMS:
1373 + case MBL_STATE_OUTSMS1:
1375 + case MBL_STATE_OUTSMS2:
1376 + if (strstr(buf, "OK")) {
1377 + pvt->state = MBL_STATE_IDLE;
1381 + /* Unsolicited responses */
1383 + if (strstr(buf, "+CMTI:")) { /* SMS Incoming... */
1384 + if ((p = strchr(buf, ','))) {
1388 + sprintf(buf, "AT+CMGR=%d\r", smsi);
1389 + rfcomm_write(pvt, buf);
1390 + pvt->state = MBL_STATE_INSMS;
1395 + } else if (s == 0) { /* Timeouts */
1396 + if (pvt->state == MBL_STATE_INIT2) { /* Some devices dont respond to AT+CIND? properly. RIM Blackberry 4 example */
1398 + rfcomm_write(pvt, "AT+CMER=3,0,0,1\r");
1399 + } else if (pvt->state == MBL_STATE_INIT3) { /* Some devices dont respond to AT+CMER=3,0,0,1 properly. VK 2020 for example */
1401 + rfcomm_write(pvt, "AT+CLIP=1\r");
1402 + } else if (pvt->state == MBL_STATE_PREIDLE) {
1403 + pvt->connected = 1;
1404 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s initialised and ready.\n", pvt->id);
1405 + pvt->state = MBL_STATE_IDLE;
1406 + } else if (pvt->state == MBL_STATE_DIAL) {
1407 + sprintf(buf, "ATD%s;\r", pvt->dial_number);
1408 + if (!rfcomm_write(pvt, buf)) {
1409 + ast_log(LOG_ERROR, "Dial failed on %s state %d\n", pvt->owner->name, pvt->state);
1410 + ast_queue_control(pvt->owner, AST_CONTROL_CONGESTION);
1411 + pvt->state = MBL_STATE_IDLE;
1413 + pvt->state = MBL_STATE_DIAL1;
1415 + } else if (pvt->state == MBL_STATE_DIAL1) {
1416 + ast_log(LOG_ERROR, "Dial failed on %s state %d\n", pvt->owner->name, pvt->state);
1417 + ast_queue_control(pvt->owner, AST_CONTROL_CONGESTION);
1418 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1419 + pvt->state = MBL_STATE_IDLE;
1420 + } else if (pvt->state == MBL_STATE_RING) { /* No CLIP?, bump it */
1421 + pvt->state = MBL_STATE_RING2;
1422 + } else if (pvt->state == MBL_STATE_HANGUP) {
1423 + if (pvt->hangup_count == 6) {
1424 + ast_debug(1, "Device %s failed to hangup after 6 tries, disconnecting.\n", pvt->id);
1427 + rfcomm_write(pvt, "AT+CHUP\r");
1428 + pvt->hangup_count++;
1429 + } else if (pvt->state == MBL_STATE_OUTSMS) {
1430 + sprintf(buf, "AT+CMGS=\"%s\"\r", pvt->dial_number);
1431 + rfcomm_write(pvt, buf);
1432 + pvt->state = MBL_STATE_OUTSMS1;
1433 + } else if (pvt->state == MBL_STATE_OUTSMS1) {
1434 + if (pvt->rfcomm_buf[0] == '>') {
1435 + sprintf(buf, "%s%c", pvt->sms_txt, 0x1a);
1436 + rfcomm_write(pvt, buf);
1437 + pvt->state = MBL_STATE_OUTSMS2;
1439 + ast_log(LOG_ERROR, "Failed to send SMS to %s on device %s\n", pvt->dial_number, pvt->id);
1440 + pvt->state = MBL_STATE_IDLE;
1442 + } else if (pvt->state == MBL_STATE_OUTSMS2) {
1443 + ast_log(LOG_ERROR, "Failed to send SMS to %s on device %s\n", pvt->dial_number, pvt->id);
1444 + pvt->state = MBL_STATE_IDLE;
1446 + } else if (s == -1) {
1447 + if (option_verbose > 2)
1448 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s has disconnected, reason (%d).\n", pvt->id, errno);
1454 + close(pvt->rfcomm_socket);
1455 + close(pvt->sco_socket);
1456 + pvt->sco_socket = -1;
1457 + pvt->connected = 0;
1458 + pvt->monitor_thread = AST_PTHREADT_NULL;
1466 + Headset Monitor Thread
1468 + This thread is spun once a headset device is discovered and considered capable of being used, i.e. supports Headset Profile,
1469 + and its configured in mobile.conf.
1470 + The thread lives for the lifetime of the bluetooth connection, and handles the 'control' side of all calls.
1474 +static void *do_monitor_headset(void *data)
1477 + struct mbl_pvt *pvt = (struct mbl_pvt *)data;
1482 + pvt->state = MBL_STATE_PREIDLE;
1486 + if (pvt->state == MBL_STATE_RING2)
1490 + s = rfcomm_read(pvt, buf, 0, t);
1492 + if ((s > 0) && (buf[0] != 0x0) && (buf[0] != '\r')) {
1493 + ast_debug(1, "rfcomm_read() (%s) [%s]\n", pvt->id, buf);
1494 + switch (pvt->state) {
1495 + case MBL_STATE_RING2:
1496 + if (strstr(buf, "AT+CKPD=")) {
1497 + ast_channel_lock(pvt->owner);
1498 + pvt->owner->fds[0] = pvt->sco_socket;
1499 + ast_log(LOG_NOTICE,"pvt-sco_socket used for fds in headphone code\n");
1500 + ast_channel_unlock(pvt->owner);
1501 + ast_queue_control(pvt->owner, AST_CONTROL_ANSWER);
1502 + pvt->state = MBL_STATE_INCOMING;
1503 + rfcomm_write(pvt, "\r\n+VGS=13\r\n");
1504 + rfcomm_write(pvt, "\r\n+VGM=13\r\n");
1507 + case MBL_STATE_INCOMING:
1508 + if (strstr(buf, "AT+CKPD=")) {
1509 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1515 + if (strstr(buf, "AT+VGS=")) {
1516 + rfcomm_write(pvt, "\r\nOK\r\n");
1517 + } else if (strstr(buf, "AT+VGM=")) {
1518 + rfcomm_write(pvt, "\r\nOK\r\n");
1520 + } else if (s == 0) { /* Timeouts */
1521 + if (pvt->state == MBL_STATE_PREIDLE) {
1522 + pvt->connected = 1;
1523 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s initialised and ready.\n", pvt->id);
1524 + pvt->state = MBL_STATE_IDLE;
1525 + } else if (pvt->state == MBL_STATE_RING) {
1526 + pvt->sco_socket = sco_connect(pvt->bdaddr);
1527 + if (pvt->sco_socket > -1) {
1528 + ast_log(LOG_NOTICE,"sco_connect returned -1 in state RING\n");
1529 + ast_setstate(pvt->owner, AST_STATE_RINGING);
1530 + ast_queue_control(pvt->owner, AST_CONTROL_RINGING);
1531 + pvt->state = MBL_STATE_RING2;
1533 + ast_queue_control(pvt->owner, AST_CONTROL_HANGUP);
1535 + } else if (pvt->state == MBL_STATE_RING2) {
1536 + rfcomm_write(pvt, "\r\nRING\r\n");
1538 + } else if (s == -1) {
1539 + if (option_verbose > 2)
1540 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s has disconnected, reason (%d).\n", pvt->id, errno);
1550 +static int start_monitor(struct mbl_pvt *pvt)
1553 + if (pvt->type == MBL_TYPE_PHONE) {
1554 + if (ast_pthread_create_background(&pvt->monitor_thread, NULL, do_monitor_phone, pvt) < 0) {
1555 + pvt->monitor_thread = AST_PTHREADT_NULL;
1559 + if (ast_pthread_create_background(&pvt->monitor_thread, NULL, do_monitor_headset, pvt) < 0) {
1560 + pvt->monitor_thread = AST_PTHREADT_NULL;
1571 + Device Discovery Thread.
1573 + This thread wakes every 'discovery_interval' seconds and trys to connect to
1574 + those configured devices which are not connected. This saves the user from having
1575 + to manually connect his/her cell phone to the asterisk box. Once a successful
1576 + connection is made, a monitor thread is spun on the device which lives for the
1577 + lifetime of the connection.
1581 +static void *do_discovery(void *data)
1584 + struct mbl_pvt *pvt = data;
1587 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
1588 + if (!pvt->connected) {
1589 + if ((pvt->rfcomm_socket = rfcomm_connect(pvt->bdaddr, pvt->rfcomm_port)) > -1) {
1591 + if (start_monitor(pvt)) {
1592 + pvt->connected = 1;
1593 + if (option_verbose > 2)
1594 + ast_verbose(VERBOSE_PREFIX_3 "Bluetooth Device %s has connected.\n", pvt->id);
1600 + sleep(discovery_interval);
1608 + This thread listens for incoming sco connections.
1609 + Although the Bluetooth Handsfree Profile Specification says that either end may initiate the audio connection,
1610 + in practice some devices (LG TU500) get upset unless they initiate the connection.
1611 + We leave all sco initiation to the device.
1612 + On an inbound sco connection, we need to find the appropriate device, and set the channel fd accordingly.
1616 +static void *do_sco_listen(void *data)
1621 + struct sockaddr_sco addr;
1622 + struct sco_options so;
1626 + socklen_t addrlen;
1627 + struct mbl_pvt *pvt;
1629 + hci_devba(0, &local);
1631 + if ((sco_socket = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_SCO)) < 0) {
1632 + ast_log(LOG_ERROR, "Unable to create sco listener socket.\n");
1635 + memset(&addr, 0, sizeof(addr));
1636 + addr.sco_family = AF_BLUETOOTH;
1637 + bacpy(&addr.sco_bdaddr, &local);
1638 + if (bind(sco_socket, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
1639 + ast_log(LOG_ERROR, "Unable to bind sco listener socket. (%d)\n", errno);
1640 + close(sco_socket);
1643 + if (setsockopt(sco_socket, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1) {
1644 + ast_log(LOG_ERROR, "Unable to setsockopt sco listener socket.\n");
1645 + close(sco_socket);
1648 + if (listen(sco_socket, 5) < 0) {
1649 + ast_log(LOG_ERROR, "Unable to listen sco listener socket.\n");
1650 + close(sco_socket);
1654 + addrlen = sizeof(struct sockaddr);
1655 + ast_log(LOG_NOTICE, "About to accept the sco_socket...\n");
1656 + if ((ns = accept(sco_socket, (struct sockaddr *)&addr, &addrlen)) > -1) {
1657 + ast_log(LOG_NOTICE, "sco_socket returns %d...\n",ns);
1658 + ba2str(&addr.sco_bdaddr, saddr);
1661 + getsockopt(ns, SOL_SCO, SCO_OPTIONS, &so, &len);
1663 + ast_debug(1, "Incoming Audio Connection from device %s MTU is %d\n", saddr, so.mtu);
1666 + AST_LIST_TRAVERSE(&devices, pvt, entry) {
1667 + if (!strcmp(pvt->bdaddr, saddr))
1671 + ast_log(LOG_NOTICE,"about to close the pvt-sco_socket and set it ns\n");
1672 + if (pvt->sco_socket != -1)
1673 + close(pvt->sco_socket);
1674 + pvt->sco_socket = ns;
1676 + ast_channel_lock(pvt->owner);
1677 + pvt->owner->fds[0] = ns;
1678 + ast_channel_unlock(pvt->owner);
1681 + ast_debug(1, "Could not find device for incoming Audio Connection.\n");
1683 + else ast_log(LOG_NOTICE, "Accept got a -1....");
1690 +static int mbl_load_config(void)
1693 + struct ast_config *cfg = NULL;
1695 + struct ast_variable *var;
1696 + const char *address, *port, *context, *type, *skip;
1697 + struct mbl_pvt *pvt;
1699 + cfg = ast_config_load(MBL_CONFIG);
1703 + for (var = ast_variable_browse(cfg, "general"); var; var = var->next) {
1704 + if (!strcasecmp(var->name, "interval"))
1705 + discovery_interval = atoi(var->value);
1708 + cat = ast_category_browse(cfg, NULL);
1710 + if (strcasecmp(cat, "general")) {
1711 + ast_debug(1, "Loading device %s.\n", cat);
1712 + address = ast_variable_retrieve(cfg, cat, "address");
1713 + port = ast_variable_retrieve(cfg, cat, "port");
1714 + context = ast_variable_retrieve(cfg, cat, "context");
1715 + ast_log(LOG_NOTICE, "context for non-general category %s was %s\n", cat, context);
1716 + type = ast_variable_retrieve(cfg, cat, "type");
1717 + skip = ast_variable_retrieve(cfg, cat, "dtmfskip");
1718 + if (address && port) {
1719 + if ((pvt = ast_malloc(sizeof(struct mbl_pvt)))) {
1720 + if (type && !strcmp(type, "headset"))
1721 + pvt->type = MBL_TYPE_HEADSET;
1723 + pvt->type = MBL_TYPE_PHONE;
1724 + ast_copy_string(pvt->id, cat, sizeof(pvt->id));
1725 + ast_copy_string(pvt->bdaddr, address, sizeof(pvt->bdaddr));
1726 + ast_copy_string(pvt->context, S_OR(context, "default"), sizeof(pvt->context));
1727 + pvt->connected = 0;
1728 + pvt->state = MBL_STATE_INIT;
1729 + pvt->rfcomm_socket = -1;
1730 + pvt->rfcomm_port = atoi(port);
1731 + pvt->rfcomm_buf[0] = 0x00;
1732 + pvt->sco_socket = -1;
1733 + pvt->monitor_thread = AST_PTHREADT_NULL;
1734 + pvt->owner = NULL;
1735 + pvt->no_callsetup = 0;
1737 + pvt->dsp = ast_dsp_new();
1739 + if ((pvt->dtmf_skip = atoi(skip)) == 0)
1740 + pvt->dtmf_skip = 200;
1742 + pvt->dtmf_skip = 200;
1743 + pvt->skip_frames = 0;
1744 + ast_dsp_set_features(pvt->dsp, DSP_FEATURE_DTMF_DETECT);
1745 + ast_dsp_digitmode(pvt->dsp, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
1746 + AST_LIST_INSERT_HEAD(&devices, pvt, entry);
1749 + ast_log(LOG_ERROR, "Device %s has no address/port configured. It wont be enabled.\n", cat);
1752 + cat = ast_category_browse(cfg, cat);
1755 + ast_config_destroy(cfg);
1761 +static int reload_module(void)
1768 +static int unload_module(void)
1771 + struct mbl_pvt *pvt;
1773 + /* First, take us out of the channel loop */
1774 + ast_channel_unregister(&mbl_tech);
1776 + /* Kill the discovery thread */
1777 + if (discovery_thread != AST_PTHREADT_NULL) {
1778 + pthread_cancel(discovery_thread);
1779 + pthread_join(discovery_thread, NULL);
1781 + /* Kill the sco listener thread */
1782 + if (sco_listener_thread != AST_PTHREADT_NULL) {
1783 + pthread_cancel(sco_listener_thread);
1784 + pthread_join(sco_listener_thread, NULL);
1786 + if ((close(sco_socket) == -1))
1787 + ast_log(LOG_ERROR, "Unable to close sco_socket %d.\n", errno);
1789 + /* Unregister the CLI & APP */
1790 + ast_cli_unregister_multiple(mbl_cli, sizeof(mbl_cli) / sizeof(mbl_cli[0]));
1791 + ast_unregister_application(app_mblstatus);
1792 + ast_unregister_application(app_mblsendsms);
1794 + /* Destroy the device list */
1795 + while ((pvt = AST_LIST_REMOVE_HEAD(&devices, entry))) {
1796 + if (pvt->monitor_thread != AST_PTHREADT_NULL) {
1797 + pthread_cancel(pvt->monitor_thread);
1798 + pthread_join(pvt->monitor_thread, NULL);
1800 + if (pvt->sco_socket > -1) {
1801 + close(pvt->sco_socket);
1803 + if (pvt->rfcomm_socket > -1) {
1804 + close(pvt->rfcomm_socket);
1806 + ast_dsp_free(pvt->dsp);
1811 + sdp_close(sdp_session);
1817 +static int load_module(void)
1823 + /* Check if we have Bluetooth, no point loading otherwise... */
1824 + dev_id = hci_get_route(NULL);
1825 + s = hci_open_dev(dev_id);
1826 + if (dev_id < 0 || s < 0) {
1827 + ast_log(LOG_ERROR, "No Bluetooth device found. Not loading module.\n");
1828 + return AST_MODULE_LOAD_DECLINE;
1831 + hci_read_voice_setting(s, &vs, 1000);
1833 + if (vs != 0x0060) {
1834 + ast_log(LOG_ERROR, "Bluetooth voice setting must be 0x0060 - see hciconfig hci0 voice.\n");
1836 + return AST_MODULE_LOAD_DECLINE;
1841 + if (!mbl_load_config()) {
1842 + ast_log(LOG_ERROR, "Unable to read config file %s. Not loading module.\n", MBL_CONFIG);
1843 + return AST_MODULE_LOAD_DECLINE;
1846 + sdp_session = sdp_register();
1848 + /* Spin the discovery thread */
1849 + if (ast_pthread_create_background(&discovery_thread, NULL, do_discovery, NULL) < 0) {
1850 + ast_log(LOG_ERROR, "Unable to create discovery thread.\n");
1851 + return AST_MODULE_LOAD_DECLINE;
1853 + /* Spin the sco listener thread */
1854 + if (ast_pthread_create_background(&sco_listener_thread, NULL, do_sco_listen, NULL) < 0) {
1855 + ast_log(LOG_ERROR, "Unable to create sco listener thread.\n");
1856 + pthread_cancel(discovery_thread);
1857 + pthread_join(discovery_thread, NULL);
1858 + return AST_MODULE_LOAD_DECLINE;
1861 + ast_cli_register_multiple(mbl_cli, sizeof(mbl_cli) / sizeof(mbl_cli[0]));
1862 + ast_register_application(app_mblstatus, mbl_status_exec, mblstatus_synopsis, mblstatus_desc);
1863 + ast_register_application(app_mblsendsms, mbl_sendsms_exec, mblsendsms_synopsis, mblsendsms_desc);
1865 + /* Make sure we can register our channel type */
1866 + if (ast_channel_register(&mbl_tech)) {
1867 + ast_log(LOG_ERROR, "Unable to register channel class %s\n", "Mobile");
1868 + return AST_MODULE_LOAD_FAILURE;
1874 +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Bluetooth Mobile Device Channel Driver",
1875 + .load = load_module,
1876 + .unload = unload_module,
1877 + .reload = reload_module,
1879 diff -Nru asterisk-addons-1.4.6.org/configs/mobile.conf.sample asterisk-addons-1.4.6/configs/mobile.conf.sample
1880 --- asterisk-addons-1.4.6.org/configs/mobile.conf.sample 1970-01-01 01:00:00.000000000 +0100
1881 +++ asterisk-addons-1.4.6/configs/mobile.conf.sample 2008-03-06 08:38:14.000000000 +0100
1888 +interval=60 ; Number of seconds between trying to connect to devices.
1890 +; The following is a list of the devices we deal with.
1891 +; Every device listed below will be available for calls in and out of Asterisk.
1892 +; Discovered devices not in this list are not available.
1893 +; Use the CLI command 'mobile search' to discover devices.
1894 +; Use the CLI command 'mobile show devices' to see device status.
1896 +; To place out through a cell phone use Dial(Mobile/[device]/NNN.....) in your dialplan.
1897 +; To call a headset use Dial(Mobile/[device]).
1900 +;address=00:12:56:90:6E:00
1902 +;context=incoming-mobile
1905 +;address=00:0F:86:0E:AE:42
1907 +;context=incoming-mobile
1910 +;address=00:0B:9E:11:74:A5
1913 diff -Nru asterisk-addons-1.4.6.org/configure.ac asterisk-addons-1.4.6/configure.ac
1914 --- asterisk-addons-1.4.6.org/configure.ac 2008-02-13 23:58:11.000000000 +0100
1915 +++ asterisk-addons-1.4.6/configure.ac 2008-03-06 08:38:14.000000000 +0100
1916 @@ -161,13 +161,14 @@
1917 # from here on down, library checking should be done in alphabetical order
1918 # by the --with option name, to make things easier for the users :-)
1920 +AST_EXT_LIB_SETUP([BLUETOOTH], [Bluetooth Support], [bluetooth])
1921 AST_EXT_LIB_SETUP([CURSES], [curses], [curses])
1922 AST_EXT_LIB_SETUP([NCURSES], [ncurses], [ncurses])
1923 AST_EXT_LIB_SETUP([MYSQLCLIENT], [mysqlclient], [mysqlclient])
1924 AST_EXT_LIB_SETUP([ASTERISK], [asterisk], [asterisk])
1926 +AST_EXT_LIB_CHECK([BLUETOOTH], [bluetooth], [ba2str], [bluetooth/bluetooth.h])
1927 AST_EXT_LIB_CHECK([CURSES], [curses], [initscr], [curses.h])
1929 AST_EXT_LIB_CHECK([NCURSES], [ncurses], [initscr], [curses.h])
1932 diff -Nru asterisk-addons-1.4.6.org/doc/chan_mobile.txt asterisk-addons-1.4.6/doc/chan_mobile.txt
1933 --- asterisk-addons-1.4.6.org/doc/chan_mobile.txt 1970-01-01 01:00:00.000000000 +0100
1934 +++ asterisk-addons-1.4.6/doc/chan_mobile.txt 2008-03-06 08:38:14.000000000 +0100
1938 +Asterisk Channel Driver to allow Bluetooth Cell/Mobile Phones to be used as FXO devices, and Headsets as FXS devices.
1942 +Multiple cell phones can be connected.
1943 +Multiple headsets can be connected.
1944 +Asterisk automatically connects to each configured cell phone / headset when it comes in range.
1945 +CLI command to discover bluetooth devices.
1946 +Inbound calls on the cell network to the cell phones are handled by Asterisk, just like inbound calls on a Zap channel.
1947 +CLI passed through on inbound calls.
1948 +Dial outbound on a cell phone using Dial(Mobile/device/nnnnnnn) in the dialplan.
1949 +Dial a headset using Dial(Mobile/device) in the dialplan.
1950 +Application MobileStatus can be used in the dialplan to see if a cell phone / headset is connected.
1951 +Supports devicestate for dialplan hinting.
1952 +Supports Inbound and Outbound SMS.
1954 +Using chan_mobile :-
1956 +In order to use chan_mobile, you must have a working bluetooth subsystem on your Asterisk box.
1957 +This means a working bluetooth adapter, and the BlueZ packages.
1959 +Any bluetooth adapter supported by the Linux kernel will do, including usb bluetooth dongles.
1961 +The BlueZ package you need is bluez-utils. If you are using a GUI then you might want to install bluez-pin also.
1962 +You also need libbluetooth, and libbluetooth-dev if you are compiling Asterisk from source.
1964 +You need to get bluetooth working with your phone before attempting to use chan_mobile.
1965 +This means 'pairing' your phone with your Asterisk box. I dont describe how to do this here as the process
1966 +differs from distro to distro. You only need to pair once.
1968 +However, the easist way to pair, is to use you cell phone to search for bluetooth devices, select your Asterisk box
1969 +and enter the requested PIN.
1971 +See www.bluez.org for other details about setting up Bluetooth under Linux.
1973 +Assuming you have bluetooth working ok:-
1975 +Load chan_mobile.so
1977 +Search for your bluetooth devices using the CLI command 'mobile search'. Be patient with this command as
1978 +it will take 8 - 10 seconds to do the discovery.
1980 +Headsets will generally have to be put into 'pairing' mode before they will show up here.
1982 +This will return something like the following :-
1984 +*CLI> mobile search
1985 +Address Name Usable Type Port
1986 +00:12:56:90:6E:00 LG TU500 Yes Phone 4
1987 +00:80:C8:35:52:78 Toaster No Headset 0
1988 +00:0B:9E:11:74:A5 Hello II Plus Yes Headset 1
1989 +00:0F:86:0E:AE:42 Daves Blackberry Yes Phone 7
1991 +This is a list of all bluetooth devices seen and whether or not they are usable with chan_cellphone.
1992 +The Address field contains the 'bd address' of the device. This is like an ethernet mac address.
1993 +The Name field is whatever is configured into the device as its name.
1994 +The Usable field tells you whether or not the device supports the Bluetooth Handsfree Profile or Headset profile.
1995 +The Type field tells you whether the device is usable as a Phone line (FXO) or a headset (FXS)
1996 +The Port field is the number to put in the configuration file.
1998 +Choose which device(s) you want to use and edit /etc/asterisk/mobile.conf. There is a sample included
1999 +with the Asterisk source under configs/mobile.conf.sample.
2001 +Assuming we want to use the devices above, mobile.conf needs to look like this :-
2003 +===================================================================================
2009 +interval=60 ; Number of seconds between trying to connect to devices.
2011 +; The following is a list of the devices we deal with.
2012 +; Every device listed below will be available for calls in and out of Asterisk.
2013 +; Discovered devices not in this list are not available.
2014 +; Use the CLI command 'mobile search' to discover devices.
2015 +; Use the CLI command 'mobile show devices' to see device status.
2017 +; To place a call use Dial(Mobile/[device]/NNN.....) in your dialplan.
2020 +address=00:12:56:90:6E:00
2022 +context=incoming-mobile
2025 +address=00:0B:9E:11:74:A5
2028 +===================================================================================
2030 +Be sure to configure the right bd address and port number from the search. If you want inbound
2031 +calls on a device to go to a specific context, add a context= line, otherwise the default will
2032 +be used. The 'id' of the device [bitinbrackets] can be anything you like, just make the unique.
2034 +If your are configuring a Headset be sure to include the type=headset line, if left out it defaults
2037 +Having done this, unload chan_mobile and load it again.
2039 +The CLI command 'mobile show devices' can be used at any time to show the status of configured devices,
2040 +and whether or not the device is capable of sending / receiving SMS via bluetooth.
2042 +*CLI> mobile show devices
2043 +ID Address Connected State SMS
2044 +blackberry 00:0F:86:0E:AE:42 Yes Free Yes
2045 +dave 00:12:56:90:6E:00 Yes Free No
2046 +headset 00:0B:9E:11:74:A5 Yes Free No
2050 +All being well Asterisk will now try and establish a connection to each configured device. If it cant
2051 +it will retry after 'interval' seconds, infinately.
2053 +This means that as your cell phone comes into range and goes out of range, Asterisk will automatically
2054 +connect and disconnect from it. You dont need to worry about it.
2056 +As each phone is connected you will see a message on the Asterisk console :-
2058 + Loaded chan_mobile.so => (Bluetooth Mobile Device Channel Driver)
2059 + -- Bluetooth Device blackberry has connected.
2060 + -- Bluetooth Device dave has connected.
2062 +If someone calls your cell phone now, Asterisk will handle the call and it will be sent into the
2063 +context you specified, or the default context. Mostly likely this means some SIP phone somewhere will
2064 +ring, pick it up and take the call.
2066 +To make outbound calls, add something to you Dialplan like the following :- (modify to suit)
2069 +exten => _9X.,1,Dial(Mobile/dave/${EXTEN:1},45)
2070 +exten => _9X.,n,Hangup
2071 +; Calls via Blackberry
2072 +exten => _8X.,1,Dial(Mobile/blackberry/${EXTEN:1},45)
2073 +exten => _8X.,n,Hangup
2075 +Pick up a SIP phone and dial 9<number of pizza shop> and the call vill go via the device 'dave' in
2078 +To incoming calls to a headset do something like this :-
2081 +exten => s,1,Dial(Mobile/headset,30)
2082 +exten => s,n,Hangup()
2084 +To dial out on a headset, you need to use some other mechanism, because the headset is not likely
2085 +to have all the needed buttons on it. res_clioriginate is good for this :-
2087 +*CLI> originate Mobile/headset extension NNNNN@context
2089 +This will call your headset, once you answer Asterisk will call NNNNN at context context
2093 +chan_mobile supports 'device status' so you can do somthing like
2095 +exten => 1234,hint,SIP/30&Mobile/dave&Mobile/blackberry
2098 +MobileStatus Application :-
2100 +chan_mobile also registers an application named MobileStatus. You can use this in your Dialplan
2101 +to determine the 'state' of a device.
2103 +For example, suppose you wanted to call dave's extension, but only if he was in the office. You could
2104 +test to see if his cell phone was attached to Asterisk, if it is dial his extension, otherwise dial his
2107 +exten => 40,1,MobileStatus(dave,DAVECELL)
2108 +exten => 40,2,GotoIf($["${DAVECELL}" = "1"]?3:5)
2109 +exten => 40,3,Dial(ZAP/g1/0427466412,45,tT)
2110 +exten => 40,4,Hangup
2111 +exten => 40,5,Dial(SIP/40,45,tT)
2112 +exten => 40,6,Hangup
2114 +MobileStatus sets the value of the given variable to :-
2116 +1 = Disconnected. i.e. Device not in range of Asterisk, or turned off etc etc
2117 +2 = Connected and Not on a call. i.e. Free
2118 +3 = Connected and on a call. i.e. Busy
2121 +SMS Sending / Receiving
2123 +If Asterisk has detected your cell phone is capable of SMS via bluetooth, you will be able to send and
2126 +Incoming SMS's cause Asterisk to create an inbound call to the context you defined in mobile.conf or the default
2127 +context if you did not define one. The call will start at extension 'sms'. Two channel variables will be available,
2128 +SMSSRC = the number of the originator of the SMS and SMSTXT which is the text of the SMS.
2129 +This is not a voice call, so grab the values of the variables and hang the call up.
2131 +So, to handle incoming SMS's, do something like the following in your dialplan
2134 +exten => sms,1,Verbose(Incoming SMS from ${SMSSRC} ${SMSTXT})
2135 +exten => sms,n,Hangup()
2137 +The above will just print the message on the console.
2139 +If you use res_jabber, you could do something like this :-
2142 +exten => sms,1,JabberSend(transport,user@jabber.somewhere.com,SMS from ${SMSRC} ${SMSTXT})
2143 +exten => sms,2,Hangup()
2145 +To send an SMS, use the application MobileSendSMS like the following :-
2147 +exten => 99,1,MobileSendSMS(dave,0427123456,Hello World)
2149 +This will send 'Hello World' via device 'dave' to '0427123456'
2154 +DTMF detection varies from phone to phone. There is a configuration variable that allows you to tune
2155 +this to your needs. e.g. in mobile.conf
2158 +address=00:12:56:90:6E:00
2160 +context=incoming-mobile
2163 +change dtmfskip to suit your phone. The default is 200. The larger the number, the more chance of missed DTMF.
2164 +The smaller the number the more chance of multiple digits being detected.
2169 +Different phone manufacturers have different interpretations of the Bluetooth Handsfree Profile Spec.
2170 +This means that not all phones work the same way, particularly in the connection setup / initialisation
2171 +sequence. I've tried to make chan_cellphone as general as possible, but it may need modification to
2172 +support some phone i've never tested.
2174 +The RIM Blackberry 7250 works extremely well. So does the LG TU500.
2176 +Some phones, most notably Sony Ericsson 'T' series, dont quite conform to the Bluetooth HFP spec.
2177 +chan_mobile will detect these and adapt accordingly. The T-610 and T-630 have been tested and
2180 +If your phone doesnt behave has expected, turn on Asterisk debugging with 'core set debug 1'.
2182 +This will log a bunch of debug messages indicating what the phone is doing, importantly the rfcomm
2183 +conversation between Asterisk and the phone. This can be used to sort out what your phone is doing
2184 +and make chan_mobile support it.
2186 +Be aware also, that just about all cell phones behave differently. For example my LG TU500 wont dial unless
2187 +the phone is a the 'idle' screen. i.e. if the phone is showing a 'menu' on the display, when you dial via
2188 +Asterisk, the call will not work. chan_mobile handles this, but there may be other phones that do
2189 +other things too...
2191 +Important: Watch what your cell phone is doing the first few times. Asterisk wont make random calls but
2192 +if chan_mobile fails to hangup for some reason and you get a huge bill from your telco, dont blame me.
2195 +Feedback, Support, Please can you make Cell Phone X work... etc :-
2197 +email me at david.bowerman at gmail.com or dseeb_ on #asterisk & #asterisk-dev irc.
2198 diff -Nru asterisk-addons-1.4.6.org/Makefile asterisk-addons-1.4.6/Makefile
2199 --- asterisk-addons-1.4.6.org/Makefile 2008-02-13 23:58:11.000000000 +0100
2200 +++ asterisk-addons-1.4.6/Makefile 2008-03-06 08:38:14.000000000 +0100
2203 gmenuconfig: gmenuselect
2205 +menuconfig: menuselect
2207 menuselect: menuselect/menuselect menuselect-tree
2208 -@menuselect/menuselect $(GLOBAL_MAKEOPTS) $(USER_MAKEOPTS) menuselect.makeopts && echo "menuselect changes saved!" || echo "menuselect changes NOT saved!"
2210 diff -Nru asterisk-addons-1.4.6.org/makeopts.in asterisk-addons-1.4.6/makeopts.in
2211 --- asterisk-addons-1.4.6.org/makeopts.in 2008-02-13 23:58:11.000000000 +0100
2212 +++ asterisk-addons-1.4.6/makeopts.in 2008-03-06 08:38:14.000000000 +0100
2214 sharedstatedir = @sharedstatedir@
2215 sysconfdir = @sysconfdir@
2217 +BLUETOOTH_LIB=@BLUETOOTH_LIB@
2218 +BLUETOOTH_INCLUDE=@BLUETOOTH_INCLUDE@
2220 CURSES_LIB=@CURSES_LIB@
2221 CURSES_INCLUDE=@CURSES_INCLUDE@