First mods

This commit is contained in:
phaseseeker 2022-10-31 01:50:09 +01:00 committed by Jerry
parent 9613917cf4
commit ac244cdd48
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
5 changed files with 94 additions and 47 deletions

View file

@ -8,9 +8,9 @@ $(PKG_CONFIG_PATH)/libpjproject.pc:
$(MAKE) -C $(PJSIP_DIR) && \ $(MAKE) -C $(PJSIP_DIR) && \
$(MAKE) -C $(PJSIP_DIR) install $(MAKE) -C $(PJSIP_DIR) install
d-modem: d-modem.c $(PKG_CONFIG_PATH)/libpjproject.pc d-modem: d-modem.c dmodem2.c $(PKG_CONFIG_PATH)/libpjproject.pc
$(CC) -o $@ $< `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject` $(CC) -g -o $@ $< `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject`
$(CC) -g -o dmodem2 dmodem2.c `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject`
slmodemd: slmodemd:
$(MAKE) -C slmodemd $(MAKE) -C slmodemd

110
d-modem.c
View file

@ -22,10 +22,17 @@
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
// test
#include <pjsua-lib/pjsua.h> #include <pjsua-lib/pjsua.h>
#define SIGNATURE PJMEDIA_SIG_CLASS_PORT_AUD('D','M') #define SIGNATURE PJMEDIA_SIG_CLASS_PORT_AUD('D','M')
#define DMODEM_DIAL_MODE 0
#define DMODEM_ANSWER_MODE 2
#define DMODEM_RING_DETECT_MODE 3
uint8_t mode = DMODEM_DIAL_MODE;
uint8_t ringing = 0;
pjsua_call_id incoming;
struct dmodem { struct dmodem {
pjmedia_port base; pjmedia_port base;
@ -92,15 +99,30 @@ static void on_call_state(pjsua_call_id call_id, pjsip_event *e) {
ci.state_text.ptr)); ci.state_text.ptr));
if (ci.state == PJSIP_INV_STATE_DISCONNECTED) { if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
close(port.sock); if(mode != DMODEM_RING_DETECT_MODE) {
if (!destroying) { close(port.sock);
destroying = true; if (!destroying) {
pjsua_destroy(); destroying = true;
exit(0); pjsua_destroy();
exit(0);
}
} }
ringing = 0;
} }
} }
static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata) {
pjsua_call_info ci;
pjsua_call_get_info(call_id, &ci);
char* tmp = malloc(pj_strlen(&ci.remote_contact)+1);
strcpy(tmp, ci.remote_contact.ptr);
tmp[pj_strlen(&ci.remote_contact)] = '\0';
printf("Incoming call from: %s\n", tmp);
free(tmp);
incoming = call_id;
ringing = 1;
}
/* Callback called by the library when call's media state has changed */ /* Callback called by the library when call's media state has changed */
static void on_call_media_state(pjsua_call_id call_id) { static void on_call_media_state(pjsua_call_id call_id) {
pjsua_call_info ci; pjsua_call_info ci;
@ -126,30 +148,22 @@ static void on_call_media_state(pjsua_call_id call_id) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
pjsua_acc_id acc_id; pjsua_acc_id acc_id;
pj_status_t status; pj_status_t status;
if (argc != 3) { if (argc != 3) {
return -1; return -1;
} }
ringing = 0;
if(!strncmp(argv[1], "++", 2)) {
mode = DMODEM_ANSWER_MODE;
} else if(!strncmp(argv[1], "rr", 2)) {
mode = DMODEM_RING_DETECT_MODE;
}
signal(SIGPIPE,SIG_IGN); signal(SIGPIPE,SIG_IGN);
char *dialstr = argv[1]; char *dialstr = argv[1];
char *sip_user = getenv("SIP_LOGIN"); char *sip_user = "dialupuser";
if (!sip_user) { char *sip_domain = "192.168.1.2";
return -1; char *sip_pass = "pppasswdModem1";
} printf("sip data: user: %s, passwd: %s, server: %s\nMODE: %d\n", sip_user, sip_pass, sip_domain, mode);
char *sip_domain = strchr(sip_user,'@');
if (!sip_domain) {
return -1;
}
*sip_domain++ = '\0';
char *sip_pass = strchr(sip_user,':');
if (!sip_pass) {
return -1;
}
*sip_pass++ = '\0';
status = pjsua_create(); status = pjsua_create();
if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status); if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status);
@ -163,6 +177,10 @@ int main(int argc, char *argv[]) {
cfg.cb.on_call_media_state = &on_call_media_state; cfg.cb.on_call_media_state = &on_call_media_state;
cfg.cb.on_call_state = &on_call_state; cfg.cb.on_call_state = &on_call_state;
if(mode == DMODEM_RING_DETECT_MODE) {
cfg.cb.on_incoming_call = &on_incoming_call;
}
pjsua_logging_config_default(&log_cfg); pjsua_logging_config_default(&log_cfg);
log_cfg.console_level = 4; log_cfg.console_level = 4;
@ -204,24 +222,25 @@ int main(int argc, char *argv[]) {
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL); status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status); if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
} }
char buf[384];
printf("Initializing pool\n");
pj_caching_pool cp; pj_caching_pool cp;
pj_caching_pool_init(&cp, NULL, 1024*1024); pj_caching_pool_init(&cp, NULL, 1024*1024);
pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL); pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL);
pj_str_t name = pj_str("dmodem"); pj_str_t name = pj_str("dmodem");
memset(&port,0,sizeof(port)); memset(&port,0,sizeof(port));
port.sock = atoi(argv[2]); // inherited from parent port.sock = atoi(argv[2]); // inherited from parent
if(mode == DMODEM_RING_DETECT_MODE)
port.sock = NULL;
pjmedia_port_info_init(&port.base.info, &name, SIGNATURE, 9600, 1, 16, 192); pjmedia_port_info_init(&port.base.info, &name, SIGNATURE, 9600, 1, 16, 192);
port.base.put_frame = dmodem_put_frame; port.base.put_frame = dmodem_put_frame;
port.base.get_frame = dmodem_get_frame; port.base.get_frame = dmodem_get_frame;
port.base.on_destroy = dmodem_on_destroy; port.base.on_destroy = dmodem_on_destroy;
char buf[384];
memset(buf,0,sizeof(buf)); memset(buf,0,sizeof(buf));
write(port.sock, buf, sizeof(buf)); write(port.sock, buf, sizeof(buf));
/* Initialization is done, now start pjsua */ /* Initialization is done, now start pjsua */
status = pjsua_start(); status = pjsua_start();
if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status); if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
@ -233,7 +252,7 @@ int main(int argc, char *argv[]) {
pj_strdup2(pool,&cfg.id,buf); pj_strdup2(pool,&cfg.id,buf);
snprintf(buf,sizeof(buf),"sip:%s",sip_domain); snprintf(buf,sizeof(buf),"sip:%s",sip_domain);
pj_strdup2(pool,&cfg.reg_uri,buf); pj_strdup2(pool,&cfg.reg_uri,buf);
cfg.register_on_acc_add = false; cfg.register_on_acc_add = mode ? true : false;
cfg.cred_count = 1; cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str("*"); cfg.cred_info[0].realm = pj_str("*");
cfg.cred_info[0].scheme = pj_str("digest"); cfg.cred_info[0].scheme = pj_str("digest");
@ -245,16 +264,33 @@ int main(int argc, char *argv[]) {
if (status != PJ_SUCCESS) error_exit("Error adding account", status); if (status != PJ_SUCCESS) error_exit("Error adding account", status);
} }
snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain); if(mode == DMODEM_DIAL_MODE) {
printf("calling %s\n",buf); snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain);
pj_str_t uri = pj_str(buf); printf("calling %s\n",buf);
pj_str_t uri = pj_str(buf);
pjsua_call_id callid; pjsua_call_id callid;
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid); status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);
if (status != PJ_SUCCESS) error_exit("Error making call", status); if (status != PJ_SUCCESS) error_exit("Error making call", status);
}
if(mode == DMODEM_ANSWER_MODE) {
pjsua_call_id id;
char* cid = strrchr(argv[1], '+');
id = atoi(cid);
status = pjsua_call_answer(id, 200, NULL, NULL);
if (status != PJ_SUCCESS) error_exit("Error answering call", status);
}
struct timespec ts = {100, 0}; struct timespec ts = {100, 0};
if(mode == DMODEM_RING_DETECT_MODE)
ts.tv_sec = 1;
time_t now = time(NULL);
while(1) { while(1) {
if(mode == DMODEM_RING_DETECT_MODE) {
if(ringing) {
char cid[11];
snprintf(cid, 10, "%d", incoming);
write(atoi(argv[2]), cid, strlen(cid));
}
}
nanosleep(&ts,NULL); nanosleep(&ts,NULL);
} }

View file

@ -1203,7 +1203,7 @@ static int modem_stop (struct modem *m)
} }
#ifdef MODEM_CONFIG_RING_DETECTOR #ifdef MODEM_CONFIG_RING_DETECTOR
if(m->rd_obj) { if(m->rd_obj) {
RD_delete(m->rd_obj); free(m->rd_obj);
m->rd_obj = NULL; m->rd_obj = NULL;
} }
#endif #endif
@ -1316,6 +1316,11 @@ static int modem_cid_start(struct modem *m, unsigned timeout)
#ifdef MODEM_CONFIG_RING_DETECTOR #ifdef MODEM_CONFIG_RING_DETECTOR
static void modem_ring_detector_process(struct modem *m, void *in, void *out, int count) static void modem_ring_detector_process(struct modem *m, void *in, void *out, int count)
{ {
if(count != 0) {
char callid[10];
strncpy(callid, in, 10);
printf("Ringing! callid:%s\n", callid);
}/*
int ret; int ret;
memset(out, 0, count*2); memset(out, 0, count*2);
ret = RD_process(m->rd_obj, in, count); ret = RD_process(m->rd_obj, in, count);
@ -1330,7 +1335,7 @@ static void modem_ring_detector_process(struct modem *m, void *in, void *out, in
} }
else if (freq > 0) { else if (freq > 0) {
MODEM_DBG("report ring end...\n"); MODEM_DBG("report ring end...\n");
/* ring finishing */ /* ring finishing *//*
m->event |= MDMEVENT_RING_CHECK; m->event |= MDMEVENT_RING_CHECK;
if (m->ring_count <= 1) if (m->ring_count <= 1)
m->ring_count = duration * freq / 1000 ; m->ring_count = duration * freq / 1000 ;
@ -1339,7 +1344,7 @@ static void modem_ring_detector_process(struct modem *m, void *in, void *out, in
else else
MODEM_ERR("RD returns %ld freq. (duration %ld)\n", MODEM_ERR("RD returns %ld freq. (duration %ld)\n",
freq, duration); freq, duration);
} }*/
#ifdef MODEM_CONFIG_CID #ifdef MODEM_CONFIG_CID
if(m->cid) if(m->cid)
modem_cid_process(m, in, out, count); modem_cid_process(m, in, out, count);
@ -1353,10 +1358,11 @@ int modem_ring_detector_start(struct modem *m)
MODEM_ERR("modem_ring_detector_start: rd_obj already exists!\n"); MODEM_ERR("modem_ring_detector_start: rd_obj already exists!\n");
return -1; return -1;
} }
m->rd_obj = RD_create(m, m->srate); m->rd_obj = malloc(sizeof(char));
m->process = modem_ring_detector_process; m->process = modem_ring_detector_process;
modem_set_hook(m, MODEM_HOOK_SNOOPING); modem_set_hook(m, MODEM_HOOK_SNOOPING);
return do_modem_start(m); return do_modem_start(m);
} }
#endif /* MODEM_CONFIG_RING_DETECTOR */ #endif /* MODEM_CONFIG_RING_DETECTOR */

View file

@ -91,7 +91,7 @@ enum MODEM_MODE {
#define MODEM_DEFAULT_COUNTRY_CODE 0xb5 /* USA */ #define MODEM_DEFAULT_COUNTRY_CODE 0xb5 /* USA */
#define MODEM_CONFIG_CID 1 #define MODEM_CONFIG_CID 0
#define MODEM_CONFIG_VOICE 1 #define MODEM_CONFIG_VOICE 1
#define MODEM_CONFIG_FAX 1 #define MODEM_CONFIG_FAX 1
#define MODEM_CONFIG_FAX_CLASS1 1 #define MODEM_CONFIG_FAX_CLASS1 1

View file

@ -600,6 +600,8 @@ static int modemap_ioctl(struct modem *m, unsigned int cmd, unsigned long arg)
if (cmd == MDMCTL_IODELAY && ret > 0) { if (cmd == MDMCTL_IODELAY && ret > 0) {
ret >>= MFMT_SHIFT(m->format); ret >>= MFMT_SHIFT(m->format);
ret += dev->delay; ret += dev->delay;
} }
return ret; return ret;
} }
@ -635,7 +637,10 @@ static int socket_start (struct modem *m)
char str[16]; char str[16];
snprintf(str,sizeof(str),"%d",sockets[0]); snprintf(str,sizeof(str),"%d",sockets[0]);
close(sockets[1]); close(sockets[1]);
ret = execl(modem_exec,modem_exec,m->dial_string,str,NULL); if(m->hook == MODEM_HOOK_SNOOPING)
ret = execl(modem_exec,modem_exec,"rr",str,NULL);
else
ret = execl(modem_exec,modem_exec,m->dial_string,str,NULL);
if (ret == -1) { if (ret == -1) {
ERR("prog: %s\n", modem_exec); ERR("prog: %s\n", modem_exec);
perror("execl"); perror("execl");
@ -945,7 +950,7 @@ static int modem_run(struct modem *m, struct device_struct *dev)
} }
if(FD_ISSET(dev->fd, &rset)) { if(FD_ISSET(dev->fd, &rset)) {
count = device_read(dev,inbuf,sizeof(inbuf)/2); count = device_read(dev,inbuf,sizeof(inbuf)/2);
if(count <= 0) { if((count <= 0) && (m->hook != MODEM_HOOK_SNOOPING)) {
if (errno == ECONNRESET) { if (errno == ECONNRESET) {
DBG("lost connection to child socket process\n"); DBG("lost connection to child socket process\n");
} else { } else {