[asterisk-commits] branch north/chan_skinny-fixup r25286 -
/team/north/chan_skinny-fixup/channels/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Mon May 8 04:11:36 MST 2006
Author: north
Date: Sat May 6 20:12:40 2006
New Revision: 25286
URL: http://svn.digium.com/view/asterisk?rev=25286&view=rev
Log:
a few cleanups
split handle_message into various handle_*_message functions, to make main function smaller.
add beginnings of support for redial softkey/button
Modified:
team/north/chan_skinny-fixup/channels/chan_skinny.c
Modified: team/north/chan_skinny-fixup/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/team/north/chan_skinny-fixup/channels/chan_skinny.c?rev=25286&r1=25285&r2=25286&view=diff
==============================================================================
--- team/north/chan_skinny-fixup/channels/chan_skinny.c (original)
+++ team/north/chan_skinny-fixup/channels/chan_skinny.c Sat May 6 20:12:40 2006
@@ -856,6 +856,7 @@
char call_forward[AST_MAX_EXTENSION];
char mailbox[AST_MAX_EXTENSION];
char musicclass[MAX_MUSICCLASS];
+ char lastnumberdialed[AST_MAX_EXTENSION]; /* Last number that was dialed - used for redial */
int curtone; /* Current tone being played */
ast_group_t callgroup;
ast_group_t pickupgroup;
@@ -1117,11 +1118,9 @@
{
struct skinny_line *l;
- l = d->lines;
- while (l) {
+ for (l = d->lines; l; l = l->next) {
if (l->instance == instance)
break;
- l = l->next;
}
if (!l) {
@@ -1166,6 +1165,21 @@
return NULL;
}
+static struct skinny_speeddial *find_speeddial_by_instance(struct skinny_device *d, int instance)
+{
+ struct skinny_speeddial *sd;
+
+ for (sd = d->speeddials; sd; sd = sd->next) {
+ if (sd->instance == instance)
+ break;
+ }
+
+ if (!sd) {
+ ast_log(LOG_WARNING, "Could not find speeddial with instance '%d' on device '%s'\n", instance, d->name);
+ }
+ return sd;
+}
+
static int transmit_response(struct skinnysession *s, skinny_req *req)
{
int res = 0;
@@ -1363,7 +1377,6 @@
if (!(req = req_alloc(4, CLEAR_DISPLAY_MESSAGE)))
return;
-//Qwell - why are we hardcoding here?
req->len = htolel(4);
if (skinnydebug)
ast_verbose("Clearing Display\n");
@@ -2411,477 +2424,281 @@
return tmp;
}
-static int handle_message(skinny_req *req, struct skinnysession *s)
-{
+static int handle_alarm_message(skinny_req *req, struct skinnysession *s)
+{
+ /* no response necessary */
+ return 1;
+}
+
+static int handle_register_message(skinny_req *req, struct skinnysession *s)
+{
+ char name[16];
+ int res;
+
+ res = skinny_register(req, s);
+ if (!res) {
+ ast_log(LOG_ERROR, "Rejecting Device %s: Device not found\n", req->data.reg.name);
+ memcpy(&name, req->data.reg.name, sizeof(req->data.reg.name));
+ if (!(req = req_alloc(sizeof(register_rej_message), REGISTER_REJ_MESSAGE)))
+ return -1;
+
+ snprintf(req->data.regrej.errMsg, sizeof(req->data.regrej.errMsg), "No Authority: %s", name);
+ transmit_response(s, req);
+ return 0;
+ }
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Device '%s' successfully registered\n", s->device->name);
+
+ if (!(req = req_alloc(sizeof(register_ack_message), REGISTER_ACK_MESSAGE)))
+ return -1;
+
+ req->data.regack.res[0] = '0';
+ req->data.regack.res[1] = '\0';
+ req->data.regack.keepAlive = htolel(keep_alive);
+ ast_copy_string(req->data.regack.dateTemplate, date_format, sizeof(req->data.regack.dateTemplate));
+ req->data.regack.res2[0] = '0';
+ req->data.regack.res2[1] = '\0';
+ req->data.regack.secondaryKeepAlive = htolel(keep_alive);
+ transmit_response(s, req);
+ if (skinnydebug)
+ ast_verbose("Requesting capabilities\n");
+
+ if (!(req = req_alloc(4, CAPABILITIES_REQ_MESSAGE)))
+ return -1;
+
+ req->len = htolel(4);
+ transmit_response(s, req);
+
+ return res;
+}
+
+static int handle_unregister_message(skinny_req *req, struct skinnysession *s)
+{
+ /* XXX Actually unregister the device */
+ return 1;
+}
+
+static int handle_headset_status_message(skinny_req *req, struct skinnysession *s)
+{
+ /* XXX umm...okay? Why do I care? */
+ return 1;
+}
+
+static int handle_register_available_lines_message(skinny_req *req, struct skinnysession *s)
+{
+ /* XXX I have no clue what this is for, but my phone was sending it, so... */
+ return 1;
+}
+
+static int handle_ip_port_message(skinny_req *req, struct skinnysession *s)
+{
+ /* no response necessary */
+ return 1;
+}
+
+static int handle_stimulus_message(skinny_req *req, struct skinnysession *s)
+{
+ struct skinny_line *l;
+ struct skinny_speeddial *sd;
struct ast_channel *c;
- struct ast_frame f = { 0, };
- struct sockaddr_in sin;
- struct sockaddr_in us;
- struct skinny_line *l;
- char name[16];
- char addr[4];
- char d;
- char iabuf[INET_ADDRSTRLEN];
- int digit;
- int res=0;
+ pthread_t t;
int event;
int instance;
- int reference;
- int status;
- int port;
- int i;
- int x;
- int y;
- time_t timer;
- struct tm *cmtime;
- pthread_t t;
- struct skinny_speeddial *sd;
-
- if ((!s->device) && (letohl(req->e) != REGISTER_MESSAGE && letohl(req->e) != ALARM_MESSAGE)) {
- ast_log(LOG_WARNING, "Client sent message #%d without first registering.\n", req->e);
- free(req);
- return 0;
- }
-
- switch(letohl(req->e)) {
- case ALARM_MESSAGE:
- /* no response necessary */
- break;
- case REGISTER_MESSAGE:
- if (skinnydebug)
- ast_verbose("Device %s is attempting to register\n", req->data.reg.name);
- res = skinny_register(req, s);
- if (!res) {
- ast_log(LOG_ERROR, "Rejecting Device %s: Device not found\n", req->data.reg.name);
- memcpy(&name, req->data.reg.name, sizeof(req->data.reg.name));
- if (!(req = req_alloc(sizeof(register_rej_message), REGISTER_REJ_MESSAGE)))
- return -1;
-
- snprintf(req->data.regrej.errMsg, sizeof(req->data.regrej.errMsg), "No Authority: %s", name);
- transmit_response(s, req);
- break;
- }
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Device '%s' successfully registered\n", s->device->name);
-
- if (!(req = req_alloc(sizeof(register_ack_message), REGISTER_ACK_MESSAGE)))
- return -1;
-
- req->data.regack.res[0] = '0';
- req->data.regack.res[1] = '\0';
- req->data.regack.keepAlive = htolel(keep_alive);
- ast_copy_string(req->data.regack.dateTemplate, date_format, sizeof(req->data.regack.dateTemplate));
- req->data.regack.res2[0] = '0';
- req->data.regack.res2[1] = '\0';
- req->data.regack.secondaryKeepAlive = htolel(keep_alive);
- transmit_response(s, req);
- if (skinnydebug)
- ast_verbose("Requesting capabilities\n");
-
- if (!(req = req_alloc(4, CAPABILITIES_REQ_MESSAGE)))
- return -1;
-
- req->len = htolel(4);
- transmit_response(s, req);
- break;
- case UNREGISTER_MESSAGE:
- /* XXX Actually unregister the device */
- break;
- case HEADSET_STATUS_MESSAGE:
- /* XXX umm...okay? Why do I care? */
- break;
- case REGISTER_AVAILABLE_LINES_MESSAGE:
- /* XXX I have no clue what this is for, but my phone was sending it, so... */
- break;
- case IP_PORT_MESSAGE:
- /* no response necessary */
- break;
- case STIMULUS_MESSAGE:
- event = letohl(req->data.stimulus.stimulus);
- instance = letohl(req->data.stimulus.stimulusInstance);
-
- switch(event) {
- case STIMULUS_REDIAL:
- /* If we can keep an array of dialed frames we can implement a quick
- and dirty redial, feeding the frames we last got into the queue
- function */
- if (skinnydebug)
- ast_verbose("Received Stimulus: Redial(%d)\n", instance);
- break;
- case STIMULUS_SPEEDDIAL:
- if (skinnydebug)
- ast_verbose("Received Stimulus: SpeedDial(%d)\n", instance);
- transmit_callstate(s, s->device->lines->instance, SKINNY_OFFHOOK, s->device->lines->callid);
- if (skinnydebug)
- ast_verbose("Attempting to Clear display on Skinny %s@%s\n",s->device->lines->name, s->device->name);
- transmit_displaymessage(s, NULL); /* clear display */
- transmit_tone(s, SKINNY_DIALTONE);
- l = s->device->lines;
- sd = s->device->speeddials;
-
- while (sd) {
- if (sd->instance == instance) {
+ int res = 0;
+
+ event = letohl(req->data.stimulus.stimulus);
+ instance = letohl(req->data.stimulus.stimulusInstance);
+
+ switch(event) {
+ case STIMULUS_REDIAL:
+ /* If we can keep an array of dialed frames we can implement a quick
+ and dirty redial, feeding the frames we last got into the queue
+ function */
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Redial(%d)\n", instance);
+
+ l = s->device->lines;
+
+ transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
+ if (skinnydebug)
+ ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, s->device->name);
+ transmit_displaymessage(s, NULL); /* clear display */
+ transmit_tone(s, SKINNY_DIALTONE);
+
+ c = skinny_new(l, AST_STATE_DOWN);
+ if(c) {
+ if (ast_strlen_zero(l->lastnumberdialed)) {
+ ast_log(LOG_WARNING, "User attempted redial, but no previously dialed number found.\n");
+ return 0;
+ }
+ if (!ast_ignore_pattern(c->context, l->lastnumberdialed)) {
+ transmit_tone(s, SKINNY_SILENCE);
+ }
+ if (ast_exists_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) {
+ if (!res || !ast_matchmore_extension(c, c->context, l->lastnumberdialed, 1, l->cid_num)) {
+ ast_copy_string(c->exten, l->lastnumberdialed, sizeof(c->exten));
+ if (!ast_strlen_zero(l->cid_num)) {
+ if (!l->hidecallerid) {
+ c->cid.cid_num = strdup(l->cid_num);
+ c->cid.cid_ani = strdup(l->cid_num);
+ }
+ }
+ ast_setstate(c, AST_STATE_RING);
+ res = ast_pbx_run(c);
+ if (res) {
+ ast_log(LOG_WARNING, "PBX exited non-zero\n");
+ transmit_tone(s, SKINNY_REORDER);
+ }
break;
}
- sd = sd->next;
+ } else if (res == 0) {
+ ast_log(LOG_DEBUG, "Not enough digits (and no ambiguous match)...\n");
+ transmit_tone(s, SKINNY_REORDER);
+ ast_hangup(c);
+ break;
}
-
- if (!sd) {
- ast_log(LOG_WARNING, "Could not find speeddial with instance %d.\n", instance);
- return 0;
+ } else {
+ ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", s->device->lines->name, s->device->name);
+ }
+ break;
+ case STIMULUS_SPEEDDIAL:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: SpeedDial(%d)\n", instance);
+
+ l = s->device->lines;
+
+ if (!(sd = find_speeddial_by_instance(s->device, instance))) {
+ return 0;
+ }
+
+ transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
+ if (skinnydebug)
+ ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, s->device->name);
+ transmit_displaymessage(s, NULL); /* clear display */
+ transmit_tone(s, SKINNY_DIALTONE);
+
+ c = skinny_new(l, AST_STATE_DOWN);
+ if(c) {
+ if (!ast_ignore_pattern(c->context, sd->exten)) {
+ transmit_tone(s, SKINNY_SILENCE);
}
-
- c = skinny_new(s->device->lines, AST_STATE_DOWN);
- if(c) {
- if (!ast_ignore_pattern(c->context, sd->exten)) {
- transmit_tone(s, SKINNY_SILENCE);
- }
- if (ast_exists_extension(c, c->context, sd->exten, 1, l->cid_num)) {
- if (!res || !ast_matchmore_extension(c, c->context, sd->exten, 1, l->cid_num)) {
- ast_copy_string(c->exten, sd->exten, sizeof(c->exten));
- if (!ast_strlen_zero(l->cid_num)) {
- if (!l->hidecallerid) {
- c->cid.cid_num = strdup(l->cid_num);
- c->cid.cid_ani = strdup(l->cid_num);
- }
+ if (ast_exists_extension(c, c->context, sd->exten, 1, l->cid_num)) {
+ if (!res || !ast_matchmore_extension(c, c->context, sd->exten, 1, l->cid_num)) {
+ ast_copy_string(c->exten, sd->exten, sizeof(c->exten));
+ if (!ast_strlen_zero(l->cid_num)) {
+ if (!l->hidecallerid) {
+ c->cid.cid_num = strdup(l->cid_num);
+ c->cid.cid_ani = strdup(l->cid_num);
}
- ast_setstate(c, AST_STATE_RING);
- res = ast_pbx_run(c);
- if (res) {
- ast_log(LOG_WARNING, "PBX exited non-zero\n");
- transmit_tone(s, SKINNY_REORDER);
- }
- break;
- } else {
}
- } else if (res == 0) {
- ast_log(LOG_DEBUG, "Not enough digits (and no ambiguous match)...\n");
- transmit_tone(s, SKINNY_REORDER);
- ast_hangup(c);
+ ast_setstate(c, AST_STATE_RING);
+ res = ast_pbx_run(c);
+ if (res) {
+ ast_log(LOG_WARNING, "PBX exited non-zero\n");
+ transmit_tone(s, SKINNY_REORDER);
+ }
break;
}
- } else {
- ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", s->device->lines->name, s->device->name);
+ } else if (res == 0) {
+ ast_log(LOG_DEBUG, "Not enough digits (and no ambiguous match)...\n");
+ transmit_tone(s, SKINNY_REORDER);
+ ast_hangup(c);
+ break;
}
- break;
- case STIMULUS_HOLD:
- /* start moh? set RTP to 0.0.0.0? */
- if (skinnydebug)
- ast_verbose("Received Stimulus: Hold(%d)\n", instance);
- break;
- case STIMULUS_TRANSFER:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Transfer(%d)\n", instance);
- transmit_tone(s, SKINNY_DIALTONE);
- /* XXX figure out how to transfer */
- break;
- case STIMULUS_CONFERENCE:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Transfer(%d)\n", instance);
- transmit_tone(s, SKINNY_DIALTONE);
- /* XXX determine the best way to pull off a conference. Meetme? */
- break;
- case STIMULUS_VOICEMAIL:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Voicemail(%d)\n", instance);
- /* XXX Find and dial voicemail extension */
- break;
- case STIMULUS_CALLPARK:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Park Call(%d)\n", instance);
- /* XXX Park the call */
- break;
- case STIMULUS_FORWARDALL:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Forward All(%d)\n", instance);
- /* Why is DND under FORWARDALL? */
- /* Because it's the same thing. */
-
- /* Do not disturb */
- transmit_tone(s, SKINNY_DIALTONE);
- if (s->device->lines->dnd != 0){
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
- s->device->lines->dnd = 0;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
- transmit_displaynotify(s, "DnD disabled",10);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
- s->device->lines->dnd = 1;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
- transmit_displaynotify(s, "DnD enabled",10);
- }
- break;
- case STIMULUS_FORWARDBUSY:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Forward Busy (%d)\n", instance);
- break;
- case STIMULUS_FORWARDNOANSWER:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Forward No Answer (%d)\n", instance);
- break;
- case STIMULUS_DISPLAY:
- /* Not sure what this is */
- if (skinnydebug)
- ast_verbose("Received Stimulus: Display(%d)\n", instance);
- break;
- case STIMULUS_LINE:
- if (skinnydebug)
- ast_verbose("Received Stimulus: Line(%d)\n", instance);
-
- l = find_line_by_instance(s->device, instance);
-
- if (!l) {
- ast_log(LOG_NOTICE, "No available lines on: %s\n", s->device->name);
- return 0;
- }
-
- /* turn the speaker on */
- transmit_speaker_mode(s, SKINNY_SPEAKERON);
- transmit_ringer_mode(s, SKINNY_RING_OFF);
- transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
-
- l->hookstate = SKINNY_OFFHOOK;
-
- if (l->outgoing) {
- /* We're answering a ringing call */
- ast_queue_control(l->owner, AST_CONTROL_ANSWER);
- transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
- transmit_tone(s, SKINNY_SILENCE);
- transmit_callstate(s, l->instance, SKINNY_CONNECTED, l->callid);
- transmit_displaypromptstatus(s, "Connected", 0, l->instance, l->callid);
- transmit_selectsoftkeys(s, l->instance, l->callid, KEYDEF_CONNECTED);
- start_rtp(l);
- ast_setstate(l->owner, AST_STATE_UP);
- } else {
- if (!l->owner) {
- transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
- if (skinnydebug)
- ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, s->device->name);
- transmit_displaymessage(s, NULL); /* clear display */
- transmit_tone(s, SKINNY_DIALTONE);
- transmit_selectsoftkeys(s, l->instance, l->callid, KEYDEF_OFFHOOK);
- c = skinny_new(l, AST_STATE_DOWN);
- if(c) {
- /* start the switch thread */
- if (ast_pthread_create(&t, NULL, skinny_ss, c)) {
- ast_log(LOG_WARNING, "Unable to create switch thread: %s\n", strerror(errno));
- ast_hangup(c);
- }
- } else {
- ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, s->device->name);
- }
- } else {
- ast_log(LOG_DEBUG, "Current sub [%s] already has owner\n", l->owner->name);
- }
- }
- break;
- default:
- if (skinnydebug)
- ast_verbose("RECEIVED UNKNOWN STIMULUS: %d(%d)\n", event, instance);
- break;
- }
- break;
- case VERSION_REQ_MESSAGE:
- if (skinnydebug)
- ast_verbose("Version Request\n");
-
- if (!(req = req_alloc(sizeof(version_res_message), VERSION_RES_MESSAGE)))
- return -1;
-
- snprintf(req->data.version.version, sizeof(req->data.version.version), s->device->version_id);
- transmit_response(s, req);
- break;
- case SERVER_REQUEST_MESSAGE:
- if (skinnydebug)
- ast_verbose("Received Server Request\n");
-
- if (!(req = req_alloc(sizeof(server_res_message), SERVER_RES_MESSAGE)))
- return -1;
-
- memcpy(req->data.serverres.server[0].serverName, ourhost,
- sizeof(req->data.serverres.server[0].serverName));
- req->data.serverres.serverListenPort[0] = htolel(ourport);
- req->data.serverres.serverIpAddr[0] = htolel(__ourip.s_addr);
- transmit_response(s, req);
- break;
- case BUTTON_TEMPLATE_REQ_MESSAGE:
- if (skinnydebug)
- ast_verbose("Buttontemplate requested\n");
-
- if (!(req = req_alloc(sizeof(button_template_res_message), BUTTON_TEMPLATE_RES_MESSAGE)))
- return -1;
-
- struct skinny_speeddial *sd;
- button_definition_template btn[42];
- int lineInstance = 1;
- int speeddialInstance = 1;
- int buttonCount = 0;
-
- memset(&btn, 0, sizeof(btn));
-
- get_button_template(s, btn);
-
- for (i=0; i<42; i++) {
- int btnSet = 0;
- switch (btn[i].buttonDefinition) {
- case BT_CUST_LINESPEEDDIAL:
- l = s->device->lines;
- sd = s->device->speeddials;
- /* assume failure */
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
-
- while (l) {
- if (l->instance == lineInstance) {
- ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance++);
- buttonCount++;
- btnSet = 1;
- break;
- }
- l = l->next;
- }
-
- if (!btnSet) {
- while (sd) {
- if (sd->instance == speeddialInstance) {
- ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance++);
- buttonCount++;
- btnSet = 1;
- break;
- }
- sd = sd->next;
- }
- }
- break;
- case BT_LINE:
- l = s->device->lines;
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
-
- while (l) {
- if (l->instance == lineInstance) {
- ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance++);
- buttonCount++;
- btnSet = 1;
- break;
- }
- l = l->next;
- }
- break;
- case BT_SPEEDDIAL:
- sd = s->device->speeddials;
- req->data.buttontemplate.definition[i].buttonDefinition = BT_NONE;
- req->data.buttontemplate.definition[i].instanceNumber = 0;
-
- while (sd) {
- if (sd->instance == speeddialInstance) {
- ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance++);
- buttonCount++;
- btnSet = 1;
- break;
- }
- sd = sd->next;
- }
- break;
- case BT_CUST_HINT:
- break;
- case BT_NONE:
- break;
- default:
- ast_verbose("Adding button: %d, %d\n", btn[i].buttonDefinition, 0);
- req->data.buttontemplate.definition[i].buttonDefinition = htolel(btn[i].buttonDefinition);
- req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
- buttonCount++;
- btnSet = 1;
- break;
- }
- }
-
- req->data.buttontemplate.buttonOffset = htolel(0);
- req->data.buttontemplate.buttonCount = htolel(buttonCount);
- req->data.buttontemplate.totalButtonCount = htolel(buttonCount);
-
- if (skinnydebug)
- ast_verbose("Sending %d template to %s@%s (%s)\n",
- s->device->type,
- s->device->lines->name,
- s->device->name,
- s->device->model);
- transmit_response(s, req);
- break;
- case SOFT_KEY_SET_REQ_MESSAGE:
- if (skinnydebug)
- ast_verbose("Received SoftKeySetReq\n");
-
- if (!(req = req_alloc(sizeof(soft_key_set_res_message), SOFT_KEY_SET_RES_MESSAGE)))
- return -1;
-
- req->data.softkeysets.softKeySetOffset = htolel(0);
- req->data.softkeysets.softKeySetCount = htolel(11);
- req->data.softkeysets.totalSoftKeySetCount = htolel(11);
- const soft_key_definitions *softkeymode = soft_key_default_definitions;
- for (x = 0; x < sizeof(soft_key_default_definitions) / sizeof(soft_key_definitions); x++) {
- const uint8_t *defaults = softkeymode->defaults;
- /* XXX I wanted to get the size of the array dynamically, but that wasn't wanting to work.
- This will have to do for now. */
- for (y = 0; y < softkeymode->count; y++) {
- for (i = 0; i < (sizeof(soft_key_template_default) / sizeof(soft_key_template_definition)); i++) {
- if (defaults[y] == i+1) {
- req->data.softkeysets.softKeySetDefinition[softkeymode->mode].softKeyTemplateIndex[y] = htolel(i+1);
- }
- }
- }
- softkeymode++;
- }
- transmit_response(s,req);
- transmit_selectsoftkeys(s, 0, 0, KEYDEF_ONHOOK);
- break;
- case SOFT_KEY_EVENT_MESSAGE:
- event = letohl(req->data.softkeyeventmessage.softKeyEvent);
- instance = letohl(req->data.softkeyeventmessage.instance);
- reference = letohl(req->data.softkeyeventmessage.reference);
+ } else {
+ ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", s->device->lines->name, s->device->name);
+ }
+ break;
+ case STIMULUS_HOLD:
+ /* start moh? set RTP to 0.0.0.0? */
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Hold(%d)\n", instance);
+ break;
+ case STIMULUS_TRANSFER:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Transfer(%d)\n", instance);
+ transmit_tone(s, SKINNY_DIALTONE);
+ /* XXX figure out how to transfer */
+ break;
+ case STIMULUS_CONFERENCE:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Transfer(%d)\n", instance);
+ transmit_tone(s, SKINNY_DIALTONE);
+ /* XXX determine the best way to pull off a conference. Meetme? */
+ break;
+ case STIMULUS_VOICEMAIL:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Voicemail(%d)\n", instance);
+ /* XXX Find and dial voicemail extension */
+ break;
+ case STIMULUS_CALLPARK:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Park Call(%d)\n", instance);
+ /* XXX Park the call */
+ break;
+ case STIMULUS_FORWARDALL:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Forward All(%d)\n", instance);
+ /* Why is DND under FORWARDALL? */
+ /* Because it's the same thing. */
+
+ /* Do not disturb */
+ transmit_tone(s, SKINNY_DIALTONE);
+ if (s->device->lines->dnd != 0){
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
+ s->device->lines->dnd = 0;
+ transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
+ transmit_displaynotify(s, "DnD disabled",10);
+ } else {
+ if (option_verbose > 2)
+ ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
+ s->device->lines->dnd = 1;
+ transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
+ transmit_displaynotify(s, "DnD enabled",10);
+ }
+ break;
+ case STIMULUS_FORWARDBUSY:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Forward Busy (%d)\n", instance);
+ break;
+ case STIMULUS_FORWARDNOANSWER:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Forward No Answer (%d)\n", instance);
+ break;
+ case STIMULUS_DISPLAY:
+ /* Not sure what this is */
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Display(%d)\n", instance);
+ break;
+ case STIMULUS_LINE:
+ if (skinnydebug)
+ ast_verbose("Received Stimulus: Line(%d)\n", instance);
l = find_line_by_instance(s->device, instance);
if (!l) {
- if (skinnydebug)
- ast_verbose("Received Softkey Event: %d(%d)\n", event, instance);
- ast_log(LOG_NOTICE, "Could not find line with instance %d on %s\n", instance, s->device->name);
return 0;
}
- switch(event) {
- case SOFTKEY_NONE:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: None(%d)\n", instance);
- break;
- case SOFTKEY_REDIAL:
- /* If we can keep an array of dialed frames we can implement a quick
- and dirty redial, feeding the frames we last got into the queue
- function */
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Redial(%d)\n", instance);
- break;
- case SOFTKEY_NEWCALL:
- /* XXX Untested */
- if (skinnydebug)
- ast_verbose("Received Softkey Event: New Call(%d)\n", instance);
-
- transmit_ringer_mode(s,SKINNY_RING_OFF);
- transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
-
- l->hookstate = SKINNY_OFFHOOK;
-
+ /* turn the speaker on */
+ transmit_speaker_mode(s, SKINNY_SPEAKERON);
+ transmit_ringer_mode(s, SKINNY_RING_OFF);
+ transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
+
+ l->hookstate = SKINNY_OFFHOOK;
+
+ if (l->outgoing) {
+ /* We're answering a ringing call */
+ ast_queue_control(l->owner, AST_CONTROL_ANSWER);
+ transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
+ transmit_tone(s, SKINNY_SILENCE);
+ transmit_callstate(s, l->instance, SKINNY_CONNECTED, l->callid);
+ transmit_displaypromptstatus(s, "Connected", 0, l->instance, l->callid);
+ transmit_selectsoftkeys(s, l->instance, l->callid, KEYDEF_CONNECTED);
+ start_rtp(l);
+ ast_setstate(l->owner, AST_STATE_UP);
+ } else {
if (!l->owner) {
transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
if (skinnydebug)
@@ -2900,417 +2717,804 @@
ast_log(LOG_WARNING, "Unable to create channel for %s@%s\n", l->name, s->device->name);
}
} else {
- ast_log(LOG_DEBUG, "Current sub [%s] already has owner\n", l->owner->name);
+ ast_log(LOG_DEBUG, "Current line [%s] already has owner\n", l->owner->name);
}
- break;
- case SOFTKEY_HOLD:
- /* start moh? set RTP to 0.0.0.0? */
+ }
+ break;
+ default:
+ if (skinnydebug)
+ ast_verbose("RECEIVED UNKNOWN STIMULUS: %d(%d)\n", event, instance);
+ break;
+ }
+ return 1;
+}
+
+static int handle_version_req_message(skinny_req *req, struct skinnysession *s)
+{
+ if (!(req = req_alloc(sizeof(version_res_message), VERSION_RES_MESSAGE)))
+ return -1;
+
+ snprintf(req->data.version.version, sizeof(req->data.version.version), s->device->version_id);
+ transmit_response(s, req);
+ return 1;
+}
+
+static int handle_server_request_message(skinny_req *req, struct skinnysession *s)
+{
+ if (!(req = req_alloc(sizeof(server_res_message), SERVER_RES_MESSAGE)))
+ return -1;
+
+ memcpy(req->data.serverres.server[0].serverName, ourhost,
+ sizeof(req->data.serverres.server[0].serverName));
+ req->data.serverres.serverListenPort[0] = htolel(ourport);
+ req->data.serverres.serverIpAddr[0] = htolel(__ourip.s_addr);
+ transmit_response(s, req);
+ return 1;
+}
+
+static int handle_button_template_req_message(skinny_req *req, struct skinnysession *s)
+{
+ struct skinny_line *l;
+ int i;
+
+ if (!(req = req_alloc(sizeof(button_template_res_message), BUTTON_TEMPLATE_RES_MESSAGE)))
+ return -1;
+
+ struct skinny_speeddial *sd;
+ button_definition_template btn[42];
+ int lineInstance = 1;
+ int speeddialInstance = 1;
+ int buttonCount = 0;
+
+ memset(&btn, 0, sizeof(btn));
+
+ get_button_template(s, btn);
+
+ for (i=0; i<42; i++) {
+ int btnSet = 0;
+ switch (btn[i].buttonDefinition) {
+ case BT_CUST_LINESPEEDDIAL:
+ l = s->device->lines;
+ sd = s->device->speeddials;
+ /* assume failure */
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
+
+ while (l) {
+ if (l->instance == lineInstance) {
+ ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance++);
+ buttonCount++;
+ btnSet = 1;
+ break;
+ }
+ l = l->next;
+ }
+
+ if (!btnSet) {
+ while (sd) {
+ if (sd->instance == speeddialInstance) {
+ ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance++);
+ buttonCount++;
+ btnSet = 1;
+ break;
+ }
+ sd = sd->next;
+ }
+ }
+ break;
+ case BT_LINE:
+ l = s->device->lines;
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_NONE);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
+
+ while (l) {
+ if (l->instance == lineInstance) {
+ ast_verbose("Adding button: %d, %d\n", BT_LINE, lineInstance);
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_LINE);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(lineInstance++);
+ buttonCount++;
+ btnSet = 1;
+ break;
+ }
+ l = l->next;
+ }
+ break;
+ case BT_SPEEDDIAL:
+ sd = s->device->speeddials;
+ req->data.buttontemplate.definition[i].buttonDefinition = BT_NONE;
+ req->data.buttontemplate.definition[i].instanceNumber = 0;
+
+ while (sd) {
+ if (sd->instance == speeddialInstance) {
+ ast_verbose("Adding button: %d, %d\n", BT_SPEEDDIAL, speeddialInstance);
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(BT_SPEEDDIAL);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(speeddialInstance++);
+ buttonCount++;
+ btnSet = 1;
+ break;
+ }
+ sd = sd->next;
+ }
+ break;
+ case BT_CUST_HINT:
+ break;
+ case BT_NONE:
+ break;
+ default:
+ ast_verbose("Adding button: %d, %d\n", btn[i].buttonDefinition, 0);
+ req->data.buttontemplate.definition[i].buttonDefinition = htolel(btn[i].buttonDefinition);
+ req->data.buttontemplate.definition[i].instanceNumber = htolel(0);
+ buttonCount++;
+ btnSet = 1;
+ break;
+ }
+ }
+
+ req->data.buttontemplate.buttonOffset = htolel(0);
+ req->data.buttontemplate.buttonCount = htolel(buttonCount);
+ req->data.buttontemplate.totalButtonCount = htolel(buttonCount);
+
+ if (skinnydebug)
+ ast_verbose("Sending %d template to %s@%s (%s)\n",
+ s->device->type,
+ s->device->lines->name,
+ s->device->name,
+ s->device->model);
+ transmit_response(s, req);
+ return 1;
+}
+
+static int handle_soft_key_set_req_message(skinny_req *req, struct skinnysession *s)
+{
+ int i;
+ int x;
+ int y;
+
+ if (!(req = req_alloc(sizeof(soft_key_set_res_message), SOFT_KEY_SET_RES_MESSAGE)))
+ return -1;
+
+ req->data.softkeysets.softKeySetOffset = htolel(0);
+ req->data.softkeysets.softKeySetCount = htolel(11);
+ req->data.softkeysets.totalSoftKeySetCount = htolel(11);
+ const soft_key_definitions *softkeymode = soft_key_default_definitions;
+ for (x = 0; x < sizeof(soft_key_default_definitions) / sizeof(soft_key_definitions); x++) {
+ const uint8_t *defaults = softkeymode->defaults;
+ /* XXX I wanted to get the size of the array dynamically, but that wasn't wanting to work.
+ This will have to do for now. */
+ for (y = 0; y < softkeymode->count; y++) {
+ for (i = 0; i < (sizeof(soft_key_template_default) / sizeof(soft_key_template_definition)); i++) {
+ if (defaults[y] == i+1) {
+ req->data.softkeysets.softKeySetDefinition[softkeymode->mode].softKeyTemplateIndex[y] = htolel(i+1);
+ }
+ }
+ }
+ softkeymode++;
+ }
+ transmit_response(s,req);
+ transmit_selectsoftkeys(s, 0, 0, KEYDEF_ONHOOK);
+ return 1;
+}
+
+static int handle_soft_key_event_message(skinny_req *req, struct skinnysession *s)
+{
+ struct skinny_line *l;
+ struct ast_channel *c;
+ pthread_t t;
+ int event;
+ int instance;
+ int reference;
+
+ event = letohl(req->data.softkeyeventmessage.softKeyEvent);
+ instance = letohl(req->data.softkeyeventmessage.instance);
+ reference = letohl(req->data.softkeyeventmessage.reference);
+
+ l = find_line_by_instance(s->device, instance);
+
+ if (!l) {
+ if (skinnydebug)
+ ast_verbose("Received Softkey Event: %d(%d)\n", event, instance);
+ return 0;
+ }
+
+ switch(event) {
+ case SOFTKEY_NONE:
+ if (skinnydebug)
+ ast_verbose("Received Softkey Event: None(%d)\n", instance);
+ break;
+ case SOFTKEY_REDIAL:
+ /* If we can keep an array of dialed frames we can implement a quick
+ and dirty redial, feeding the frames we last got into the queue
+ function */
+ if (skinnydebug)
+ ast_verbose("Received Softkey Event: Redial(%d)\n", instance);
+ break;
+ case SOFTKEY_NEWCALL:
+ /* XXX Untested */
+ if (skinnydebug)
+ ast_verbose("Received Softkey Event: New Call(%d)\n", instance);
+
+ transmit_ringer_mode(s,SKINNY_RING_OFF);
+ transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
+
+ l->hookstate = SKINNY_OFFHOOK;
+
+ if (!l->owner) {
+ transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
if (skinnydebug)
- ast_verbose("Received Softkey Event: Hold(%d)\n", instance);
- break;
- case SOFTKEY_TRNSFER:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Transfer(%d)\n", instance);
+ ast_verbose("Attempting to Clear display on Skinny %s@%s\n", l->name, s->device->name);
+ transmit_displaymessage(s, NULL); /* clear display */
transmit_tone(s, SKINNY_DIALTONE);
- /* XXX figure out how to transfer */
- break;
- case SOFTKEY_CFWDALL:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Forward All(%d)\n", instance);
-
- /* Do not disturb */
- transmit_tone(s, SKINNY_DIALTONE);
- if (s->device->lines->dnd != 0){
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Disabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
- s->device->lines->dnd = 0;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_ON);
- transmit_displaynotify(s, "DnD disabled",10);
- } else {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Enabling DND on %s@%s\n",s->device->lines->name,s->device->lines->name);
- s->device->lines->dnd = 1;
- transmit_lamp_indication(s, STIMULUS_FORWARDALL, 1, SKINNY_LAMP_OFF);
- transmit_displaynotify(s, "DnD enabled",10);
- }
- break;
- case SOFTKEY_CFWDBUSY:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Forward Busy (%d)\n", instance);
- break;
- case SOFTKEY_CFWDNOANSWER:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Forward No Answer (%d)\n", instance);
- break;
- case SOFTKEY_BKSPC:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Backspace(%d)\n", instance);
- break;
- case SOFTKEY_ENDCALL:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: End Call(%d)\n", instance);
-
- if (l->hookstate == SKINNY_ONHOOK) {
- /* Something else already put us back on hook */
- break;
- }
- l->cxmode = SKINNY_CX_RECVONLY;
- l->hookstate = SKINNY_ONHOOK;
- transmit_callstate(s, l->instance, l->hookstate, l->callid);
- if (skinnydebug)
- ast_verbose("Skinny %s@%s went on hook\n", l->name, s->device->name);
- if (l->transfer && (l->owner && l->next && l->next->owner) && ((!l->outgoing) || (l->next && !l->next->outgoing))) {
- /* We're allowed to transfer, we have two active calls and
- we made at least one of the calls. Let's try and transfer */
-
-#if 0
- if ((res = attempt_transfer(p)) < 0) {
- if (l->next && l->next->owner) {
- l->next->alreadygone = 1;
- ast_queue_hangup(l->next->owner, 1);
- }
- } else if (res) {
- ast_log(LOG_WARNING, "Transfer attempt failed\n");
- return -1;
- }
-#endif
- } else {
- /* Hangup the current call */
- /* If there is another active call, skinny_hangup will ring the phone with the other call */
- if (l->owner) {
- l->alreadygone = 1;
- ast_queue_hangup(l->owner);
- } else {
- ast_log(LOG_WARNING, "Skinny(%s@%s-%d) channel already destroyed\n",
- l->name, s->device->name, l->callid);
- }
- }
- if ((l->hookstate == SKINNY_ONHOOK) && (l->next && !l->next->rtp)) {
- do_housekeeping(s);
- }
- break;
- case SOFTKEY_RESUME:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Resume(%d)\n", instance);
- break;
- case SOFTKEY_ANSWER:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Answer(%d)\n", instance);
-
- transmit_ringer_mode(s,SKINNY_RING_OFF);
- transmit_lamp_indication(s, STIMULUS_LINE, l->instance, SKINNY_LAMP_ON);
-
- l->hookstate = SKINNY_OFFHOOK;
-
- if (l->outgoing) {
- /* We're answering a ringing call */
- ast_queue_control(l->owner, AST_CONTROL_ANSWER);
- transmit_callstate(s, l->instance, SKINNY_OFFHOOK, l->callid);
- transmit_tone(s, SKINNY_SILENCE);
- transmit_callstate(s, l->instance, SKINNY_CONNECTED, l->callid);
- transmit_selectsoftkeys(s, l->instance, l->callid, KEYDEF_CONNECTED);
- start_rtp(l);
- ast_setstate(l->owner, AST_STATE_UP);
- }
- break;
- case SOFTKEY_INFO:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Info(%d)\n", instance);
- break;
- case SOFTKEY_CONFRN:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Transfer(%d)\n", instance);
- transmit_tone(s, SKINNY_DIALTONE);
- /* XXX determine the best way to pull off a conference. Meetme? */
- break;
- case SOFTKEY_PARK:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Park Call(%d)\n", instance);
- /* XXX Park the call */
- break;
- case SOFTKEY_JOIN:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Join(%d)\n", instance);
- break;
- case SOFTKEY_MEETME:
- /* XXX How is this different from CONFRN? */
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Meetme(%d)\n", instance);
- break;
- case SOFTKEY_PICKUP:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: None(%d)\n", instance);
- break;
- case SOFTKEY_GPICKUP:
- if (skinnydebug)
- ast_verbose("Received Softkey Event: Group Pickup (%d)\n", instance);
- break;
- default:
- if (skinnydebug)
- ast_verbose("Received unknown Softkey Event: %d(%d)\n", event, instance);
- break;
- }
- break;
- case SOFT_KEY_TEMPLATE_REQ_MESSAGE:
- if (skinnydebug)
- ast_verbose("Received SoftKey Template Request\n");
-
- if (!(req = req_alloc(sizeof(soft_key_template_res_message), SOFT_KEY_TEMPLATE_RES_MESSAGE)))
- return -1;
-
[... 786 lines stripped ...]
More information about the asterisk-commits
mailing list