Version 0.1.3 from FTP
[asterisk/asterisk.git] / channels / chan_modem.c
index 7c6fedb..052091e 100755 (executable)
@@ -49,6 +49,9 @@ static char mtype[80] = "autodetect";
 /* Default context for incoming calls */
 static char context[AST_MAX_EXTENSION]= "default";
 
+/* Default language */
+static char language[MAX_LANGUAGE] = "";
+
 /* Initialization String */
 static char initstr[AST_MAX_INIT_STR] = "ATE1Q0";
 
@@ -271,8 +274,13 @@ static int modem_setup(struct ast_modem_pvt *p, int baudrate)
           mode.  Set the baud rate, etc.  */
        char identity[256];
        char *ident = NULL;
+       char etx[2] = { 0x10, 0x03 };
        if (option_debug)
                ast_log(LOG_DEBUG, "Setting up modem %s\n", p->dev);
+       if (ast_modem_send(p, etx, 2)) {
+               ast_log(LOG_WARNING, "Failed to send ETX?\n");
+               return -1;
+       }
        if (ast_modem_send(p, "\r\n", 2)) {
                ast_log(LOG_WARNING, "Failed to send enter?\n");
                return -1;
@@ -419,7 +427,6 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
                snprintf(tmp->name, sizeof(tmp->name), "Modem[%s]/%s", i->mc->name, i->dev + 5);
                tmp->type = type;
                tmp->fd = i->fd;
-               /* XXX Switching formats silently causes kernel panics XXX */
                tmp->format = i->mc->formats;
                tmp->state = state;
                if (state == AST_STATE_RING)
@@ -433,7 +440,9 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
                tmp->pvt->write = modem_write;
                strncpy(tmp->context, i->context, sizeof(tmp->context));
                if (strlen(i->cid))
-                       strncpy(tmp->callerid, i->cid, sizeof(tmp->callerid));
+                       tmp->callerid = strdup(i->cid);
+               if (strlen(i->language))
+                       strncpy(tmp->language,i->language, sizeof(tmp->language));
                i->owner = tmp;
                pthread_mutex_lock(&usecnt_lock);
                usecnt++;
@@ -443,6 +452,7 @@ struct ast_channel *ast_modem_new(struct ast_modem_pvt *i, int state)
                        if (ast_pbx_start(tmp)) {
                                ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
                                ast_hangup(tmp);
+                               tmp = NULL;
                        }
                }
        } else
@@ -454,6 +464,12 @@ static void modem_mini_packet(struct ast_modem_pvt *i)
 {
        struct ast_frame *fr;
        fr = i->mc->read(i);
+       if (fr->frametype == AST_FRAME_CONTROL) {
+               if (fr->subclass == AST_CONTROL_RING) {
+                       ast_modem_new(i, AST_STATE_RING);
+                       restart_monitor();
+               }
+       }
 }
 
 static void *do_monitor(void *data)
@@ -590,6 +606,7 @@ static struct ast_modem_pvt *mkif(char *iface)
                        free(tmp);
                        return NULL;
                }
+               strncpy(tmp->language, language, sizeof(tmp->language));
                tmp->f = fdopen(tmp->fd, "w+");
                /* Disable buffering */
                setvbuf(tmp->f, NULL, _IONBF,0);
@@ -701,10 +718,10 @@ int load_module()
                                ast_verbose(VERBOSE_PREFIX_2 "Loading modem driver %s", driver);
                                
                        if (ast_load_resource(driver)) {
-                               ast_log(LOG_ERROR, "Failed to laod driver %s\n", driver);
+                               ast_log(LOG_ERROR, "Failed to load driver %s\n", driver);
                                ast_destroy(cfg);
-                               unload_module();
                                pthread_mutex_unlock(&iflock);
+                               unload_module();
                                return -1;
                        }
                } else if (!strcasecmp(v->name, "mode")) {
@@ -726,6 +743,8 @@ int load_module()
                        dialtype = toupper(v->value[0]);
                } else if (!strcasecmp(v->name, "context")) {
                        strncpy(context, v->value, sizeof(context));
+               } else if (!strcasecmp(v->name, "language")) {
+                       strncpy(language, v->value, sizeof(language));
                }
                v = v->next;
        }
@@ -742,8 +761,6 @@ int load_module()
        return 0;
 }
 
-
-
 int unload_module()
 {
        struct ast_modem_pvt *p, *pl;