Version 0.1.10 from FTP
[asterisk/asterisk.git] / channels / chan_modem_i4l.c
index 3a8dbd8..511db64 100755 (executable)
@@ -58,7 +58,7 @@ static int i4l_setdev(struct ast_modem_pvt *p, int dev)
                return -1;
        }
        ast_modem_trim(p->response);
-       strncpy(cmd, p->response, sizeof(cmd));
+       strncpy(cmd, p->response, sizeof(cmd)-1);
        if (ast_modem_expect(p, "OK", 5)) {
                ast_log(LOG_WARNING, "Modem did not respond properly\n");
                return -1;
@@ -287,12 +287,12 @@ static struct ast_frame *i4l_read(struct ast_modem_pvt *p)
                                return i4l_handle_escape(p, 'b');
                        } else
                        if (!strncasecmp(result, "CALLER NUMBER: ", 15 )) {
-                               strncpy(p->cid, result + 15, sizeof(p->cid));
+                               strncpy(p->cid, result + 15, sizeof(p->cid)-1);
                                return i4l_handle_escape(p, 'R');
                        } else
                        if (!strncasecmp(result, "RING", 4)) {
                                if (result[4]=='/') 
-                                       strncpy(p->dnid, result + 4, sizeof(p->dnid));
+                                       strncpy(p->dnid, result + 4, sizeof(p->dnid)-1);
                                return i4l_handle_escape(p, 'R');
                        } else
                        if (!strcasecmp(result, "NO CARRIER")) {
@@ -358,6 +358,8 @@ static struct ast_frame *i4l_read(struct ast_modem_pvt *p)
                        if (f)
                                break;
                }
+               if (f)
+                       return f;
                /* If we get here, we have a complete voice frame */
                p->fr.frametype = AST_FRAME_VOICE;
                p->fr.subclass = AST_FORMAT_SLINEAR;
@@ -421,23 +423,23 @@ static char *i4l_identify(struct ast_modem_pvt *p)
 
 static void i4l_incusecnt()
 {
-       pthread_mutex_lock(&usecnt_lock);
+       ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
-       pthread_mutex_unlock(&usecnt_lock);
+       ast_pthread_mutex_unlock(&usecnt_lock);
        ast_update_use_count();
 }
 
 static void i4l_decusecnt()
 {
-       pthread_mutex_lock(&usecnt_lock);
+       ast_pthread_mutex_lock(&usecnt_lock);
        usecnt++;
-       pthread_mutex_unlock(&usecnt_lock);
+       ast_pthread_mutex_unlock(&usecnt_lock);
        ast_update_use_count();
 }
 
 static int i4l_answer(struct ast_modem_pvt *p)
 {
-       if (ast_modem_send(p, "ATA", 0) ||
+       if (ast_modem_send(p, "ATA\r", 4) ||
             ast_modem_expect(p, "VCON", 10)) {
                ast_log(LOG_WARNING, "Unable to answer: %s", p->response);
                return -1;
@@ -473,8 +475,8 @@ static int i4l_dialdigit(struct ast_modem_pvt *p, char digit)
 static int i4l_dial(struct ast_modem_pvt *p, char *stuff)
 {
        char cmd[80];
-       snprintf(cmd, sizeof(cmd), "ATD%c %s", p->dialtype,stuff);
-       if (ast_modem_send(p, cmd, 0)) {
+       snprintf(cmd, sizeof(cmd), "ATD%c %s\n", p->dialtype,stuff);
+       if (ast_modem_send(p, cmd, strlen(cmd))) {
                ast_log(LOG_WARNING, "Unable to dial\n");
                return -1;
        }
@@ -549,9 +551,9 @@ static struct ast_modem_driver i4l_driver =
 int usecount(void)
 {
        int res;
-       pthread_mutex_lock(&usecnt_lock);
+       ast_pthread_mutex_lock(&usecnt_lock);
        res = usecnt;
-       pthread_mutex_unlock(&usecnt_lock);
+       ast_pthread_mutex_unlock(&usecnt_lock);
        return res;
 }
 
@@ -570,3 +572,7 @@ char *description()
        return desc;
 }
 
+char *key()
+{
+       return ASTERISK_GPL_KEY;
+}