clang-format modem and serial passthrough related files
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#define SOCKET int
|
# define SOCKET int
|
||||||
#else
|
#else
|
||||||
#include <winsock2.h>
|
# include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
# include <ws2tcpip.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum net_socket_types
|
enum net_socket_types {
|
||||||
{
|
|
||||||
/* Only TCP is supported for now. */
|
/* Only TCP is supported for now. */
|
||||||
NET_SOCKET_TCP
|
NET_SOCKET_TCP
|
||||||
};
|
};
|
||||||
@@ -17,8 +16,8 @@ void plat_netsocket_close(SOCKET socket);
|
|||||||
|
|
||||||
SOCKET plat_netsocket_accept(SOCKET socket);
|
SOCKET plat_netsocket_accept(SOCKET socket);
|
||||||
int plat_netsocket_connected(SOCKET socket); /* Returns -1 on trouble. */
|
int plat_netsocket_connected(SOCKET socket); /* Returns -1 on trouble. */
|
||||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port);
|
int plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port);
|
||||||
|
|
||||||
/* Returns 0 in case of inability to send. -1 in case of errors. */
|
/* Returns 0 in case of inability to send. -1 in case of errors. */
|
||||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock);
|
int plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock);
|
||||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock);
|
int plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock);
|
||||||
|
@@ -75,21 +75,18 @@ typedef enum ResTypes {
|
|||||||
ResNOANSWER
|
ResNOANSWER
|
||||||
} ResTypes;
|
} ResTypes;
|
||||||
|
|
||||||
enum modem_types
|
enum modem_types {
|
||||||
{
|
|
||||||
MODEM_TYPE_SLIP = 1,
|
MODEM_TYPE_SLIP = 1,
|
||||||
MODEM_TYPE_PPP = 2,
|
MODEM_TYPE_PPP = 2,
|
||||||
MODEM_TYPE_TCPIP = 3
|
MODEM_TYPE_TCPIP = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum modem_mode_t
|
typedef enum modem_mode_t {
|
||||||
{
|
|
||||||
MODEM_MODE_COMMAND = 0,
|
MODEM_MODE_COMMAND = 0,
|
||||||
MODEM_MODE_DATA = 1
|
MODEM_MODE_DATA = 1
|
||||||
} modem_mode_t;
|
} modem_mode_t;
|
||||||
|
|
||||||
typedef enum modem_slip_stage_t
|
typedef enum modem_slip_stage_t {
|
||||||
{
|
|
||||||
MODEM_SLIP_STAGE_USERNAME,
|
MODEM_SLIP_STAGE_USERNAME,
|
||||||
MODEM_SLIP_STAGE_PASSWORD
|
MODEM_SLIP_STAGE_PASSWORD
|
||||||
} modem_slip_stage_t;
|
} modem_slip_stage_t;
|
||||||
@@ -98,14 +95,12 @@ typedef enum modem_slip_stage_t
|
|||||||
#define NUMBER_BUFFER_SIZE 128
|
#define NUMBER_BUFFER_SIZE 128
|
||||||
#define PHONEBOOK_SIZE 200
|
#define PHONEBOOK_SIZE 200
|
||||||
|
|
||||||
typedef struct modem_phonebook_entry_t
|
typedef struct modem_phonebook_entry_t {
|
||||||
{
|
|
||||||
char phone[NUMBER_BUFFER_SIZE];
|
char phone[NUMBER_BUFFER_SIZE];
|
||||||
char address[NUMBER_BUFFER_SIZE];
|
char address[NUMBER_BUFFER_SIZE];
|
||||||
} modem_phonebook_entry_t;
|
} modem_phonebook_entry_t;
|
||||||
|
|
||||||
typedef struct modem_t
|
typedef struct modem_t {
|
||||||
{
|
|
||||||
uint8_t mac[6];
|
uint8_t mac[6];
|
||||||
serial_t *serial;
|
serial_t *serial;
|
||||||
uint32_t baudrate;
|
uint32_t baudrate;
|
||||||
@@ -177,20 +172,25 @@ typedef struct modem_t
|
|||||||
#define MREG_GUARD_TIME 12
|
#define MREG_GUARD_TIME 12
|
||||||
#define MREG_DTR_DELAY 25
|
#define MREG_DTR_DELAY 25
|
||||||
|
|
||||||
static void modem_do_command(modem_t* modem, int repeat);
|
static void modem_do_command(modem_t *modem, int repeat);
|
||||||
static void modem_accept_incoming_call(modem_t* modem);
|
static void modem_accept_incoming_call(modem_t *modem);
|
||||||
|
|
||||||
extern ssize_t local_getline(char **buf, size_t *bufsiz, FILE *fp);
|
extern ssize_t local_getline(char **buf, size_t *bufsiz, FILE *fp);
|
||||||
|
|
||||||
// https://stackoverflow.com/a/122974
|
// https://stackoverflow.com/a/122974
|
||||||
char *trim(char *str)
|
char *
|
||||||
|
trim(char *str)
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
char *frontp = str;
|
char *frontp = str;
|
||||||
char *endp = NULL;
|
char *endp = NULL;
|
||||||
|
|
||||||
if( str == NULL ) { return NULL; }
|
if (str == NULL) {
|
||||||
if( str[0] == '\0' ) { return str; }
|
return NULL;
|
||||||
|
}
|
||||||
|
if (str[0] == '\0') {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
endp = str + len;
|
endp = str + len;
|
||||||
@@ -198,15 +198,16 @@ char *trim(char *str)
|
|||||||
/* Move the front and back pointers to address the first non-whitespace
|
/* Move the front and back pointers to address the first non-whitespace
|
||||||
* characters from each end.
|
* characters from each end.
|
||||||
*/
|
*/
|
||||||
while( isspace((unsigned char) *frontp) ) { ++frontp; }
|
while (isspace((unsigned char) *frontp)) {
|
||||||
if( endp != frontp )
|
++frontp;
|
||||||
{
|
}
|
||||||
while( isspace((unsigned char) *(--endp)) && endp != frontp ) {}
|
if (endp != frontp) {
|
||||||
|
while (isspace((unsigned char) *(--endp)) && endp != frontp) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
if( frontp != str && endp == frontp )
|
if (frontp != str && endp == frontp)
|
||||||
*str = '\0';
|
*str = '\0';
|
||||||
else if( str + len - 1 != endp )
|
else if (str + len - 1 != endp)
|
||||||
*(endp + 1) = '\0';
|
*(endp + 1) = '\0';
|
||||||
|
|
||||||
/* Shift the string so that it starts at str so that if it's dynamically
|
/* Shift the string so that it starts at str so that if it's dynamically
|
||||||
@@ -214,9 +215,10 @@ char *trim(char *str)
|
|||||||
* of endp to mean the front of the string buffer now.
|
* of endp to mean the front of the string buffer now.
|
||||||
*/
|
*/
|
||||||
endp = str;
|
endp = str;
|
||||||
if( frontp != str )
|
if (frontp != str) {
|
||||||
{
|
while (*frontp) {
|
||||||
while( *frontp ) { *endp++ = *frontp++; }
|
*endp++ = *frontp++;
|
||||||
|
}
|
||||||
*endp = '\0';
|
*endp = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,11 +226,11 @@ char *trim(char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_read_phonebook_file(modem_t* modem, const char* path)
|
modem_read_phonebook_file(modem_t *modem, const char *path)
|
||||||
{
|
{
|
||||||
FILE* file = plat_fopen(path, "r");
|
FILE *file = plat_fopen(path, "r");
|
||||||
char* buf = NULL;
|
char *buf = NULL;
|
||||||
char* buf2 = NULL;
|
char *buf2 = NULL;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
if (!file)
|
if (!file)
|
||||||
return;
|
return;
|
||||||
@@ -274,9 +276,10 @@ modem_read_phonebook_file(modem_t* modem, const char* path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_echo(modem_t* modem, uint8_t c)
|
modem_echo(modem_t *modem, uint8_t c)
|
||||||
{
|
{
|
||||||
if (modem->echo && fifo8_num_free(&modem->data_pending)) fifo8_push(&modem->data_pending, c);
|
if (modem->echo && fifo8_num_free(&modem->data_pending))
|
||||||
|
fifo8_push(&modem->data_pending, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t
|
||||||
@@ -289,8 +292,8 @@ modem_scan_number(char **scan)
|
|||||||
if (c == 0)
|
if (c == 0)
|
||||||
break;
|
break;
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
ret*=10;
|
ret *= 10;
|
||||||
ret+=c-'0';
|
ret += c - '0';
|
||||||
*scan = *scan + 1;
|
*scan = *scan + 1;
|
||||||
} else
|
} else
|
||||||
break;
|
break;
|
||||||
@@ -315,33 +318,32 @@ modem_speed_changed(void *priv)
|
|||||||
|
|
||||||
timer_stop(&dev->host_to_serial_timer);
|
timer_stop(&dev->host_to_serial_timer);
|
||||||
/* FIXME: do something to dev->baudrate */
|
/* FIXME: do something to dev->baudrate */
|
||||||
timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double)dev->baudrate) * 9);
|
timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double) dev->baudrate) * 9);
|
||||||
#if 0
|
#if 0
|
||||||
serial_clear_fifo(dev->serial);
|
serial_clear_fifo(dev->serial);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_send_line(modem_t* modem, const char* line)
|
modem_send_line(modem_t *modem, const char *line)
|
||||||
{
|
{
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
||||||
fifo8_push_all(&modem->data_pending, (uint8_t*)line, strlen(line));
|
fifo8_push_all(&modem->data_pending, (uint8_t *) line, strlen(line));
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_send_number(modem_t* modem, uint32_t val)
|
modem_send_number(modem_t *modem, uint32_t val)
|
||||||
{
|
{
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_LF_CHAR]);
|
||||||
|
|
||||||
fifo8_push(&modem->data_pending, val / 100 + '0');
|
fifo8_push(&modem->data_pending, val / 100 + '0');
|
||||||
val = val%100;
|
val = val % 100;
|
||||||
fifo8_push(&modem->data_pending, val / 10 + '0');
|
fifo8_push(&modem->data_pending, val / 10 + '0');
|
||||||
val = val%10;
|
val = val % 10;
|
||||||
fifo8_push(&modem->data_pending, val + '0');
|
fifo8_push(&modem->data_pending, val + '0');
|
||||||
|
|
||||||
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
fifo8_push(&modem->data_pending, modem->reg[MREG_CR_CHAR]);
|
||||||
@@ -391,9 +393,8 @@ process_tx_packet(modem_t *modem, uint8_t *p, uint32_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
send_tx_packet:
|
send_tx_packet:
|
||||||
if (received)
|
if (received) {
|
||||||
{
|
uint8_t *buf = calloc(received + 14, 1);
|
||||||
uint8_t* buf = calloc(received + 14, 1);
|
|
||||||
buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = 0xFF;
|
buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = 0xFF;
|
||||||
buf[6] = buf[7] = buf[8] = buf[9] = buf[10] = buf[11] = 0xFC;
|
buf[6] = buf[7] = buf[8] = buf[9] = buf[10] = buf[11] = 0xFC;
|
||||||
buf[12] = 0x08;
|
buf[12] = 0x08;
|
||||||
@@ -407,7 +408,7 @@ send_tx_packet:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_data_mode_process_byte(modem_t* modem, uint8_t data)
|
modem_data_mode_process_byte(modem_t *modem, uint8_t data)
|
||||||
{
|
{
|
||||||
if (modem->reg[MREG_ESCAPE_CHAR] <= 127) {
|
if (modem->reg[MREG_ESCAPE_CHAR] <= 127) {
|
||||||
if (modem->plusinc >= 1 && modem->plusinc <= 3 && modem->reg[MREG_ESCAPE_CHAR] == data) {
|
if (modem->plusinc >= 1 && modem->plusinc <= 3 && modem->reg[MREG_ESCAPE_CHAR] == data) {
|
||||||
@@ -421,7 +422,7 @@ modem_data_mode_process_byte(modem_t* modem, uint8_t data)
|
|||||||
if (modem->tx_count < 0x10000 && modem->connected) {
|
if (modem->tx_count < 0x10000 && modem->connected) {
|
||||||
modem->tx_pkt_ser_line[modem->tx_count++] = data;
|
modem->tx_pkt_ser_line[modem->tx_count++] = data;
|
||||||
if (data == END && !modem->tcpIpMode) {
|
if (data == END && !modem->tcpIpMode) {
|
||||||
process_tx_packet(modem, modem->tx_pkt_ser_line, (uint32_t)modem->tx_count);
|
process_tx_packet(modem, modem->tx_pkt_ser_line, (uint32_t) modem->tx_count);
|
||||||
modem->tx_count = 0;
|
modem->tx_count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -430,7 +431,7 @@ modem_data_mode_process_byte(modem_t* modem, uint8_t data)
|
|||||||
static void
|
static void
|
||||||
host_to_modem_cb(void *priv)
|
host_to_modem_cb(void *priv)
|
||||||
{
|
{
|
||||||
modem_t* modem = (modem_t*)priv;
|
modem_t *modem = (modem_t *) priv;
|
||||||
|
|
||||||
if (modem->in_warmup)
|
if (modem->in_warmup)
|
||||||
goto no_write_to_machine;
|
goto no_write_to_machine;
|
||||||
@@ -460,13 +461,13 @@ host_to_modem_cb(void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
no_write_to_machine:
|
no_write_to_machine:
|
||||||
timer_on_auto(&modem->host_to_serial_timer, (1000000.0 / (double)modem->baudrate) * (double)9);
|
timer_on_auto(&modem->host_to_serial_timer, (1000000.0 / (double) modem->baudrate) * (double) 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_write(UNUSED(serial_t *s), void *priv, uint8_t txval)
|
modem_write(UNUSED(serial_t *s), void *priv, uint8_t txval)
|
||||||
{
|
{
|
||||||
modem_t* modem = (modem_t*)priv;
|
modem_t *modem = (modem_t *) priv;
|
||||||
|
|
||||||
if (modem->mode == MODEM_MODE_COMMAND) {
|
if (modem->mode == MODEM_MODE_COMMAND) {
|
||||||
if (modem->cmdpos < 2) {
|
if (modem->cmdpos < 2) {
|
||||||
@@ -518,28 +519,54 @@ modem_write(UNUSED(serial_t *s), void *priv, uint8_t txval)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void modem_send_res(modem_t* modem, const ResTypes response) {
|
void
|
||||||
|
modem_send_res(modem_t *modem, const ResTypes response)
|
||||||
|
{
|
||||||
char response_str_connect[256] = { 0 };
|
char response_str_connect[256] = { 0 };
|
||||||
const char* response_str = NULL;
|
const char *response_str = NULL;
|
||||||
uint32_t code = -1;
|
uint32_t code = -1;
|
||||||
|
|
||||||
snprintf(response_str_connect, sizeof(response_str_connect), "CONNECT %u", modem->baudrate);
|
snprintf(response_str_connect, sizeof(response_str_connect), "CONNECT %u", modem->baudrate);
|
||||||
|
|
||||||
switch (response) {
|
switch (response) {
|
||||||
case ResOK: code = 0; response_str = "OK"; break;
|
case ResOK:
|
||||||
case ResCONNECT: code = 1; response_str = response_str_connect; break;
|
code = 0;
|
||||||
case ResRING: code = 2; response_str = "RING"; break;
|
response_str = "OK";
|
||||||
case ResNOCARRIER: code = 3; response_str = "NO CARRIER"; break;
|
break;
|
||||||
case ResERROR: code = 4; response_str = "ERROR"; break;
|
case ResCONNECT:
|
||||||
case ResNODIALTONE: code = 6; response_str = "NO DIALTONE"; break;
|
code = 1;
|
||||||
case ResBUSY: code = 7; response_str = "BUSY"; break;
|
response_str = response_str_connect;
|
||||||
case ResNOANSWER: code = 8; response_str = "NO ANSWER"; break;
|
break;
|
||||||
case ResNONE: return;
|
case ResRING:
|
||||||
|
code = 2;
|
||||||
|
response_str = "RING";
|
||||||
|
break;
|
||||||
|
case ResNOCARRIER:
|
||||||
|
code = 3;
|
||||||
|
response_str = "NO CARRIER";
|
||||||
|
break;
|
||||||
|
case ResERROR:
|
||||||
|
code = 4;
|
||||||
|
response_str = "ERROR";
|
||||||
|
break;
|
||||||
|
case ResNODIALTONE:
|
||||||
|
code = 6;
|
||||||
|
response_str = "NO DIALTONE";
|
||||||
|
break;
|
||||||
|
case ResBUSY:
|
||||||
|
code = 7;
|
||||||
|
response_str = "BUSY";
|
||||||
|
break;
|
||||||
|
case ResNOANSWER:
|
||||||
|
code = 8;
|
||||||
|
response_str = "NO ANSWER";
|
||||||
|
break;
|
||||||
|
case ResNONE:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modem->doresponse != 1) {
|
if (modem->doresponse != 1) {
|
||||||
if (modem->doresponse == 2 && (response == ResRING ||
|
if (modem->doresponse == 2 && (response == ResRING || response == ResCONNECT || response == ResNOCARRIER)) {
|
||||||
response == ResCONNECT || response == ResNOCARRIER)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
modem_log("Modem response: %s\n", response_str);
|
modem_log("Modem response: %s\n", response_str);
|
||||||
@@ -560,7 +587,7 @@ void modem_send_res(modem_t* modem, const ResTypes response) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_enter_idle_state(modem_t* modem)
|
modem_enter_idle_state(modem_t *modem)
|
||||||
{
|
{
|
||||||
timer_disable(&modem->dtr_timer);
|
timer_disable(&modem->dtr_timer);
|
||||||
modem->connected = false;
|
modem->connected = false;
|
||||||
@@ -570,33 +597,33 @@ modem_enter_idle_state(modem_t* modem)
|
|||||||
modem->tcpIpConnInProgress = 0;
|
modem->tcpIpConnInProgress = 0;
|
||||||
modem->tcpIpConnCounter = 0;
|
modem->tcpIpConnCounter = 0;
|
||||||
|
|
||||||
if (modem->waitingclientsocket != (SOCKET)-1)
|
if (modem->waitingclientsocket != (SOCKET) -1)
|
||||||
plat_netsocket_close(modem->waitingclientsocket);
|
plat_netsocket_close(modem->waitingclientsocket);
|
||||||
|
|
||||||
if (modem->clientsocket != (SOCKET)-1)
|
if (modem->clientsocket != (SOCKET) -1)
|
||||||
plat_netsocket_close(modem->clientsocket);
|
plat_netsocket_close(modem->clientsocket);
|
||||||
|
|
||||||
modem->clientsocket = modem->waitingclientsocket = (SOCKET)-1;
|
modem->clientsocket = modem->waitingclientsocket = (SOCKET) -1;
|
||||||
if (modem->serversocket != (SOCKET)-1) {
|
if (modem->serversocket != (SOCKET) -1) {
|
||||||
modem->waitingclientsocket = plat_netsocket_accept(modem->serversocket);
|
modem->waitingclientsocket = plat_netsocket_accept(modem->serversocket);
|
||||||
while (modem->waitingclientsocket != (SOCKET)-1) {
|
while (modem->waitingclientsocket != (SOCKET) -1) {
|
||||||
plat_netsocket_close(modem->waitingclientsocket);
|
plat_netsocket_close(modem->waitingclientsocket);
|
||||||
modem->waitingclientsocket = plat_netsocket_accept(modem->serversocket);
|
modem->waitingclientsocket = plat_netsocket_accept(modem->serversocket);
|
||||||
}
|
}
|
||||||
plat_netsocket_close(modem->serversocket);
|
plat_netsocket_close(modem->serversocket);
|
||||||
modem->serversocket = (SOCKET)-1;
|
modem->serversocket = (SOCKET) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modem->waitingclientsocket != (SOCKET)-1)
|
if (modem->waitingclientsocket != (SOCKET) -1)
|
||||||
plat_netsocket_close(modem->waitingclientsocket);
|
plat_netsocket_close(modem->waitingclientsocket);
|
||||||
|
|
||||||
modem->waitingclientsocket = (SOCKET)-1;
|
modem->waitingclientsocket = (SOCKET) -1;
|
||||||
modem->tcpIpMode = false;
|
modem->tcpIpMode = false;
|
||||||
modem->tcpIpConnInProgress = false;
|
modem->tcpIpConnInProgress = false;
|
||||||
|
|
||||||
if (modem->listen_port) {
|
if (modem->listen_port) {
|
||||||
modem->serversocket = plat_netsocket_create_server(NET_SOCKET_TCP, modem->listen_port);
|
modem->serversocket = plat_netsocket_create_server(NET_SOCKET_TCP, modem->listen_port);
|
||||||
if (modem->serversocket == (SOCKET)-1) {
|
if (modem->serversocket == (SOCKET) -1) {
|
||||||
pclog("Failed to set up server on port %d\n", modem->listen_port);
|
pclog("Failed to set up server on port %d\n", modem->listen_port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -608,7 +635,7 @@ modem_enter_idle_state(modem_t* modem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_enter_connected_state(modem_t* modem)
|
modem_enter_connected_state(modem_t *modem)
|
||||||
{
|
{
|
||||||
modem_send_res(modem, ResCONNECT);
|
modem_send_res(modem, ResCONNECT);
|
||||||
modem->mode = MODEM_MODE_DATA;
|
modem->mode = MODEM_MODE_DATA;
|
||||||
@@ -625,7 +652,7 @@ modem_enter_connected_state(modem_t* modem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_reset(modem_t* modem)
|
modem_reset(modem_t *modem)
|
||||||
{
|
{
|
||||||
modem->dcdmode = 1;
|
modem->dcdmode = 1;
|
||||||
modem_enter_idle_state(modem);
|
modem_enter_idle_state(modem);
|
||||||
@@ -639,7 +666,7 @@ modem_reset(modem_t* modem)
|
|||||||
modem->plusinc = 0;
|
modem->plusinc = 0;
|
||||||
modem->dtrmode = 2;
|
modem->dtrmode = 2;
|
||||||
|
|
||||||
memset(&modem->reg,0,sizeof(modem->reg));
|
memset(&modem->reg, 0, sizeof(modem->reg));
|
||||||
modem->reg[MREG_AUTOANSWER_COUNT] = 0; // no autoanswer
|
modem->reg[MREG_AUTOANSWER_COUNT] = 0; // no autoanswer
|
||||||
modem->reg[MREG_RING_COUNT] = 1;
|
modem->reg[MREG_RING_COUNT] = 1;
|
||||||
modem->reg[MREG_ESCAPE_CHAR] = '+';
|
modem->reg[MREG_ESCAPE_CHAR] = '+';
|
||||||
@@ -655,19 +682,16 @@ modem_reset(modem_t* modem)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_dial(modem_t* modem, const char* str)
|
modem_dial(modem_t *modem, const char *str)
|
||||||
{
|
{
|
||||||
modem->tcpIpConnCounter = 0;
|
modem->tcpIpConnCounter = 0;
|
||||||
modem->tcpIpMode = false;
|
modem->tcpIpMode = false;
|
||||||
if (!strncmp(str, "0.0.0.0", sizeof("0.0.0.0") - 1))
|
if (!strncmp(str, "0.0.0.0", sizeof("0.0.0.0") - 1)) {
|
||||||
{
|
|
||||||
modem_log("Turning on SLIP\n");
|
modem_log("Turning on SLIP\n");
|
||||||
modem_enter_connected_state(modem);
|
modem_enter_connected_state(modem);
|
||||||
modem->numberinprogress[0] = 0;
|
modem->numberinprogress[0] = 0;
|
||||||
modem->tcpIpMode = false;
|
modem->tcpIpMode = false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
char buf[NUMBER_BUFFER_SIZE] = "";
|
char buf[NUMBER_BUFFER_SIZE] = "";
|
||||||
strncpy(buf, str, sizeof(buf) - 1);
|
strncpy(buf, str, sizeof(buf) - 1);
|
||||||
strncpy(modem->lastnumber, str, sizeof(modem->lastnumber) - 1);
|
strncpy(modem->lastnumber, str, sizeof(modem->lastnumber) - 1);
|
||||||
@@ -675,12 +699,11 @@ modem_dial(modem_t* modem, const char* str)
|
|||||||
|
|
||||||
// Scan host for port
|
// Scan host for port
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
char * hasport = strrchr(buf,':');
|
char *hasport = strrchr(buf, ':');
|
||||||
if (hasport) {
|
if (hasport) {
|
||||||
*hasport++ = 0;
|
*hasport++ = 0;
|
||||||
port = (uint16_t)atoi(hasport);
|
port = (uint16_t) atoi(hasport);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
port = 23;
|
port = 23;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -705,7 +728,7 @@ modem_dial(modem_t* modem, const char* str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
is_next_token(const char* a, size_t N, const char *b)
|
is_next_token(const char *a, size_t N, const char *b)
|
||||||
{
|
{
|
||||||
// Is 'b' at least as long as 'a'?
|
// Is 'b' at least as long as 'a'?
|
||||||
size_t N_without_null = N - 1;
|
size_t N_without_null = N - 1;
|
||||||
@@ -714,7 +737,9 @@ is_next_token(const char* a, size_t N, const char *b)
|
|||||||
return (strncmp(a, b, N_without_null) == 0);
|
return (strncmp(a, b, N_without_null) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *modem_get_address_from_phonebook(modem_t* modem, const char *input) {
|
static const char *
|
||||||
|
modem_get_address_from_phonebook(modem_t *modem, const char *input)
|
||||||
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (i = 0; i < modem->entries_num; i++) {
|
for (i = 0; i < modem->entries_num; i++) {
|
||||||
if (strcmp(input, modem->entries[i].phone) == 0)
|
if (strcmp(input, modem->entries[i].phone) == 0)
|
||||||
@@ -725,7 +750,7 @@ static const char *modem_get_address_from_phonebook(modem_t* modem, const char *
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_do_command(modem_t* modem, int repeat)
|
modem_do_command(modem_t *modem, int repeat)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char *scanbuf = NULL;
|
char *scanbuf = NULL;
|
||||||
@@ -782,10 +807,11 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
modem_send_res(modem, ResERROR);
|
modem_send_res(modem, ResERROR);
|
||||||
return;
|
return;
|
||||||
case 'D': { // Dial.
|
case 'D':
|
||||||
|
{ // Dial.
|
||||||
char buffer[NUMBER_BUFFER_SIZE];
|
char buffer[NUMBER_BUFFER_SIZE];
|
||||||
char obuffer[NUMBER_BUFFER_SIZE];
|
char obuffer[NUMBER_BUFFER_SIZE];
|
||||||
char * foundstr = &scanbuf[0];
|
char *foundstr = &scanbuf[0];
|
||||||
const char *mappedaddr = NULL;
|
const char *mappedaddr = NULL;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
|
|
||||||
@@ -865,10 +891,14 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
size_t k = 0;
|
size_t k = 0;
|
||||||
size_t foundlen2 = strlen(foundstr);
|
size_t foundlen2 = strlen(foundstr);
|
||||||
for (i = 0; i < foundlen2; i++) {
|
for (i = 0; i < foundlen2; i++) {
|
||||||
if (i == 0 && foundstr[0] == '0') continue;
|
if (i == 0 && foundstr[0] == '0')
|
||||||
if (i == 1 && foundstr[0] == '0' && foundstr[1] == '0') continue;
|
continue;
|
||||||
if (foundstr[i] == '0' && foundstr[i-1] == '.') continue;
|
if (i == 1 && foundstr[0] == '0' && foundstr[1] == '0')
|
||||||
if (foundstr[i] == '0' && foundstr[i-1] == '0' && foundstr[i-2] == '.') continue;
|
continue;
|
||||||
|
if (foundstr[i] == '0' && foundstr[i - 1] == '.')
|
||||||
|
continue;
|
||||||
|
if (foundstr[i] == '0' && foundstr[i - 1] == '0' && foundstr[i - 2] == '.')
|
||||||
|
continue;
|
||||||
obuffer[k++] = foundstr[i];
|
obuffer[k++] = foundstr[i];
|
||||||
}
|
}
|
||||||
obuffer[k] = 0;
|
obuffer[k] = 0;
|
||||||
@@ -880,20 +910,32 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
case 'I': // Some strings about firmware
|
case 'I': // Some strings about firmware
|
||||||
switch (modem_scan_number(&scanbuf)) {
|
switch (modem_scan_number(&scanbuf)) {
|
||||||
case 3: modem_send_line(modem, "86Box Emulated Modem Firmware V1.00"); break;
|
case 3:
|
||||||
case 4: modem_send_line(modem, "Modem compiled for 86Box version " EMU_VERSION); break;
|
modem_send_line(modem, "86Box Emulated Modem Firmware V1.00");
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
modem_send_line(modem, "Modem compiled for 86Box version " EMU_VERSION);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'E': // Echo on/off
|
case 'E': // Echo on/off
|
||||||
switch (modem_scan_number(&scanbuf)) {
|
switch (modem_scan_number(&scanbuf)) {
|
||||||
case 0: modem->echo = false; break;
|
case 0:
|
||||||
case 1: modem->echo = true; break;
|
modem->echo = false;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
modem->echo = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
switch (modem_scan_number(&scanbuf)) {
|
switch (modem_scan_number(&scanbuf)) {
|
||||||
case 0: modem->numericresponse = true; break;
|
case 0:
|
||||||
case 1: modem->numericresponse = false; break;
|
modem->numericresponse = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
modem->numericresponse = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'H': // Hang up
|
case 'H': // Hang up
|
||||||
@@ -939,7 +981,8 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
case 'Z': { // Reset and load profiles
|
case 'Z':
|
||||||
|
{ // Reset and load profiles
|
||||||
// scan the number away, if any
|
// scan the number away, if any
|
||||||
modem_scan_number(&scanbuf);
|
modem_scan_number(&scanbuf);
|
||||||
if (modem->connected)
|
if (modem->connected)
|
||||||
@@ -949,7 +992,8 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
case ' ': // skip space
|
case ' ': // skip space
|
||||||
break;
|
break;
|
||||||
case 'Q': {
|
case 'Q':
|
||||||
|
{
|
||||||
// Response options
|
// Response options
|
||||||
// 0 = all on, 1 = all off,
|
// 0 = all on, 1 = all off,
|
||||||
// 2 = no ring and no connect/carrier in answermode
|
// 2 = no ring and no connect/carrier in answermode
|
||||||
@@ -963,11 +1007,12 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'S': { // Registers
|
case 'S':
|
||||||
|
{ // Registers
|
||||||
const uint32_t index = modem_scan_number(&scanbuf);
|
const uint32_t index = modem_scan_number(&scanbuf);
|
||||||
if (index >= 100) {
|
if (index >= 100) {
|
||||||
modem_send_res(modem, ResERROR);
|
modem_send_res(modem, ResERROR);
|
||||||
return; //goto ret_none;
|
return; // goto ret_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (scanbuf[0] == ' ')
|
while (scanbuf[0] == ' ')
|
||||||
@@ -980,8 +1025,7 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
const uint32_t val = modem_scan_number(&scanbuf);
|
const uint32_t val = modem_scan_number(&scanbuf);
|
||||||
modem->reg[index] = val;
|
modem->reg[index] = val;
|
||||||
break;
|
break;
|
||||||
}
|
} else if (scanbuf[0] == '?') { // get register
|
||||||
else if (scanbuf[0] == '?') { // get register
|
|
||||||
modem_send_number(modem, modem->reg[index]);
|
modem_send_number(modem, modem->reg[index]);
|
||||||
scanbuf++;
|
scanbuf++;
|
||||||
break;
|
break;
|
||||||
@@ -992,10 +1036,12 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
// GetPortNumber(), index, reg[index]);
|
// GetPortNumber(), index, reg[index]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '&': { // & escaped commands
|
case '&':
|
||||||
|
{ // & escaped commands
|
||||||
char cmdchar = modem_fetch_character(&scanbuf);
|
char cmdchar = modem_fetch_character(&scanbuf);
|
||||||
switch(cmdchar) {
|
switch (cmdchar) {
|
||||||
case 'C': {
|
case 'C':
|
||||||
|
{
|
||||||
const uint32_t val = modem_scan_number(&scanbuf);
|
const uint32_t val = modem_scan_number(&scanbuf);
|
||||||
if (val < 2)
|
if (val < 2)
|
||||||
modem->dcdmode = val;
|
modem->dcdmode = val;
|
||||||
@@ -1005,7 +1051,8 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'K': {
|
case 'K':
|
||||||
|
{
|
||||||
const uint32_t val = modem_scan_number(&scanbuf);
|
const uint32_t val = modem_scan_number(&scanbuf);
|
||||||
if (val < 5)
|
if (val < 5)
|
||||||
modem->flowcontrol = val;
|
modem->flowcontrol = val;
|
||||||
@@ -1015,7 +1062,8 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'D': {
|
case 'D':
|
||||||
|
{
|
||||||
const uint32_t val = modem_scan_number(&scanbuf);
|
const uint32_t val = modem_scan_number(&scanbuf);
|
||||||
if (val < 4)
|
if (val < 4)
|
||||||
modem->dtrmode = val;
|
modem->dtrmode = val;
|
||||||
@@ -1033,7 +1081,8 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\\': { // \ escaped commands
|
case '\\':
|
||||||
|
{ // \ escaped commands
|
||||||
char cmdchar = modem_fetch_character(&scanbuf);
|
char cmdchar = modem_fetch_character(&scanbuf);
|
||||||
switch (cmdchar) {
|
switch (cmdchar) {
|
||||||
case 'N':
|
case 'N':
|
||||||
@@ -1058,7 +1107,7 @@ modem_do_command(modem_t* modem, int repeat)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_dtr_callback_timer(void* priv)
|
modem_dtr_callback_timer(void *priv)
|
||||||
{
|
{
|
||||||
modem_t *dev = (modem_t *) priv;
|
modem_t *dev = (modem_t *) priv;
|
||||||
if (dev->connected) {
|
if (dev->connected) {
|
||||||
@@ -1082,7 +1131,7 @@ modem_dtr_callback_timer(void* priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
modem_dtr_callback(serial_t* serial, int status, void *priv)
|
modem_dtr_callback(serial_t *serial, int status, void *priv)
|
||||||
{
|
{
|
||||||
modem_t *dev = (modem_t *) priv;
|
modem_t *dev = (modem_t *) priv;
|
||||||
dev->dtrstate = !!status;
|
dev->dtrstate = !!status;
|
||||||
@@ -1093,7 +1142,7 @@ modem_dtr_callback(serial_t* serial, int status, void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fifo8_resize_2x(Fifo8* fifo)
|
fifo8_resize_2x(Fifo8 *fifo)
|
||||||
{
|
{
|
||||||
uint32_t pos = 0;
|
uint32_t pos = 0;
|
||||||
uint32_t size = fifo->capacity * 2;
|
uint32_t size = fifo->capacity * 2;
|
||||||
@@ -1101,7 +1150,7 @@ fifo8_resize_2x(Fifo8* fifo)
|
|||||||
if (!used)
|
if (!used)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint8_t* temp_buf = calloc(fifo->capacity * 2, 1);
|
uint8_t *temp_buf = calloc(fifo->capacity * 2, 1);
|
||||||
if (!temp_buf) {
|
if (!temp_buf) {
|
||||||
fatal("net_modem: Out Of Memory!\n");
|
fatal("net_modem: Out Of Memory!\n");
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1167,8 @@ fifo8_resize_2x(Fifo8* fifo)
|
|||||||
|
|
||||||
#define TEL_CLIENT 0
|
#define TEL_CLIENT 0
|
||||||
#define TEL_SERVER 1
|
#define TEL_SERVER 1
|
||||||
void modem_process_telnet(modem_t* modem, uint8_t *data, uint32_t size)
|
void
|
||||||
|
modem_process_telnet(modem_t *modem, uint8_t *data, uint32_t size)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
for (i = 0; i < size; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
@@ -1135,14 +1185,20 @@ void modem_process_telnet(modem_t* modem, uint8_t *data, uint32_t size)
|
|||||||
}
|
}
|
||||||
switch (modem->telClient.command) {
|
switch (modem->telClient.command) {
|
||||||
case 251: /* Will */
|
case 251: /* Will */
|
||||||
if (c == 0) modem->telClient.binary[TEL_SERVER] = true;
|
if (c == 0)
|
||||||
if (c == 1) modem->telClient.echo[TEL_SERVER] = true;
|
modem->telClient.binary[TEL_SERVER] = true;
|
||||||
if (c == 3) modem->telClient.supressGA[TEL_SERVER] = true;
|
if (c == 1)
|
||||||
|
modem->telClient.echo[TEL_SERVER] = true;
|
||||||
|
if (c == 3)
|
||||||
|
modem->telClient.supressGA[TEL_SERVER] = true;
|
||||||
break;
|
break;
|
||||||
case 252: /* Won't */
|
case 252: /* Won't */
|
||||||
if (c == 0) modem->telClient.binary[TEL_SERVER] = false;
|
if (c == 0)
|
||||||
if (c == 1) modem->telClient.echo[TEL_SERVER] = false;
|
modem->telClient.binary[TEL_SERVER] = false;
|
||||||
if (c == 3) modem->telClient.supressGA[TEL_SERVER] = false;
|
if (c == 1)
|
||||||
|
modem->telClient.echo[TEL_SERVER] = false;
|
||||||
|
if (c == 3)
|
||||||
|
modem->telClient.supressGA[TEL_SERVER] = false;
|
||||||
break;
|
break;
|
||||||
case 253: /* Do */
|
case 253: /* Do */
|
||||||
if (c == 0) {
|
if (c == 0) {
|
||||||
@@ -1220,8 +1276,7 @@ void modem_process_telnet(modem_t* modem, uint8_t *data, uint32_t size)
|
|||||||
static int
|
static int
|
||||||
modem_rx(void *priv, uint8_t *buf, int io_len)
|
modem_rx(void *priv, uint8_t *buf, int io_len)
|
||||||
{
|
{
|
||||||
#if 1
|
modem_t *modem = (modem_t *) priv;
|
||||||
modem_t* modem = (modem_t*)priv;
|
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
|
|
||||||
if (modem->tcpIpMode)
|
if (modem->tcpIpMode)
|
||||||
@@ -1265,7 +1320,6 @@ modem_rx(void *priv, uint8_t *buf, int io_len)
|
|||||||
}
|
}
|
||||||
fifo8_push(&modem->rx_data, END);
|
fifo8_push(&modem->rx_data, END);
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -1275,14 +1329,14 @@ modem_rcr_cb(UNUSED(struct serial_s *serial), void *priv)
|
|||||||
|
|
||||||
timer_stop(&dev->host_to_serial_timer);
|
timer_stop(&dev->host_to_serial_timer);
|
||||||
/* FIXME: do something to dev->baudrate */
|
/* FIXME: do something to dev->baudrate */
|
||||||
timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double)dev->baudrate) * (double) 9);
|
timer_on_auto(&dev->host_to_serial_timer, (1000000.0 / (double) dev->baudrate) * (double) 9);
|
||||||
#if 0
|
#if 0
|
||||||
serial_clear_fifo(dev->serial);
|
serial_clear_fifo(dev->serial);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
modem_accept_incoming_call(modem_t* modem)
|
modem_accept_incoming_call(modem_t *modem)
|
||||||
{
|
{
|
||||||
if (modem->waitingclientsocket != -1) {
|
if (modem->waitingclientsocket != -1) {
|
||||||
modem->clientsocket = modem->waitingclientsocket;
|
modem->clientsocket = modem->waitingclientsocket;
|
||||||
@@ -1298,7 +1352,7 @@ static void
|
|||||||
modem_cmdpause_timer_callback(void *priv)
|
modem_cmdpause_timer_callback(void *priv)
|
||||||
{
|
{
|
||||||
modem_t *modem = (modem_t *) priv;
|
modem_t *modem = (modem_t *) priv;
|
||||||
uint32_t guard_threashold = 0;
|
uint32_t guard_threshold = 0;
|
||||||
timer_on_auto(&modem->cmdpause_timer, 1000);
|
timer_on_auto(&modem->cmdpause_timer, 1000);
|
||||||
|
|
||||||
if (modem->tcpIpConnInProgress) {
|
if (modem->tcpIpConnInProgress) {
|
||||||
@@ -1349,8 +1403,7 @@ modem_cmdpause_timer_callback(void *priv)
|
|||||||
if (modem->ringing) {
|
if (modem->ringing) {
|
||||||
if (modem->ringtimer <= 0) {
|
if (modem->ringtimer <= 0) {
|
||||||
modem->reg[MREG_RING_COUNT]++;
|
modem->reg[MREG_RING_COUNT]++;
|
||||||
if ((modem->reg[MREG_AUTOANSWER_COUNT] > 0) &&
|
if ((modem->reg[MREG_AUTOANSWER_COUNT] > 0) && (modem->reg[MREG_RING_COUNT] >= modem->reg[MREG_AUTOANSWER_COUNT])) {
|
||||||
(modem->reg[MREG_RING_COUNT] >= modem->reg[MREG_AUTOANSWER_COUNT])) {
|
|
||||||
modem_accept_incoming_call(modem);
|
modem_accept_incoming_call(modem);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1368,8 +1421,7 @@ modem_cmdpause_timer_callback(void *priv)
|
|||||||
modem->tx_count = 0;
|
modem->tx_count = 0;
|
||||||
fifo8_reset(&modem->rx_data);
|
fifo8_reset(&modem->rx_data);
|
||||||
}
|
}
|
||||||
}
|
} else if (modem->connected && modem->tcpIpMode) {
|
||||||
else if (modem->connected && modem->tcpIpMode) {
|
|
||||||
if (modem->tx_count) {
|
if (modem->tx_count) {
|
||||||
int wouldblock = 0;
|
int wouldblock = 0;
|
||||||
int res = plat_netsocket_send(modem->clientsocket, modem->tx_pkt_ser_line, modem->tx_count, &wouldblock);
|
int res = plat_netsocket_send(modem->clientsocket, modem->tx_pkt_ser_line, modem->tx_count, &wouldblock);
|
||||||
@@ -1411,8 +1463,8 @@ modem_cmdpause_timer_callback(void *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
modem->cmdpause++;
|
modem->cmdpause++;
|
||||||
guard_threashold = (uint32_t)(modem->reg[MREG_GUARD_TIME] * 20);
|
guard_threshold = (uint32_t) (modem->reg[MREG_GUARD_TIME] * 20);
|
||||||
if (modem->cmdpause > guard_threashold) {
|
if (modem->cmdpause > guard_threshold) {
|
||||||
if (modem->plusinc == 0) {
|
if (modem->plusinc == 0) {
|
||||||
modem->plusinc = 1;
|
modem->plusinc = 1;
|
||||||
} else if (modem->plusinc == 4) {
|
} else if (modem->plusinc == 4) {
|
||||||
@@ -1428,11 +1480,10 @@ modem_cmdpause_timer_callback(void *priv)
|
|||||||
static void *
|
static void *
|
||||||
modem_init(const device_t *info)
|
modem_init(const device_t *info)
|
||||||
{
|
{
|
||||||
modem_t* modem = (modem_t*)calloc(1, sizeof(modem_t));
|
modem_t *modem = (modem_t *) calloc(1, sizeof(modem_t));
|
||||||
const char* phonebook_file = NULL;
|
const char *phonebook_file = NULL;
|
||||||
memset(modem->mac, 0xfc, 6);
|
memset(modem->mac, 0xfc, 6);
|
||||||
|
|
||||||
|
|
||||||
modem->port = device_get_config_int("port");
|
modem->port = device_get_config_int("port");
|
||||||
modem->baudrate = device_get_config_int("baudrate");
|
modem->baudrate = device_get_config_int("baudrate");
|
||||||
modem->listen_port = device_get_config_int("listen_port");
|
modem->listen_port = device_get_config_int("listen_port");
|
||||||
@@ -1460,9 +1511,10 @@ modem_init(const device_t *info)
|
|||||||
return modem;
|
return modem;
|
||||||
}
|
}
|
||||||
|
|
||||||
void modem_close(void *priv)
|
void
|
||||||
|
modem_close(void *priv)
|
||||||
{
|
{
|
||||||
modem_t* modem = (modem_t*)priv;
|
modem_t *modem = (modem_t *) priv;
|
||||||
modem->listen_port = 0;
|
modem->listen_port = 0;
|
||||||
modem_reset(modem);
|
modem_reset(modem);
|
||||||
fifo8_destroy(&modem->data_pending);
|
fifo8_destroy(&modem->data_pending);
|
||||||
|
@@ -19,7 +19,8 @@
|
|||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include <winerror.h>
|
#include <winerror.h>
|
||||||
|
|
||||||
SOCKET plat_netsocket_create(int type)
|
SOCKET
|
||||||
|
plat_netsocket_create(int type)
|
||||||
{
|
{
|
||||||
SOCKET socket = -1;
|
SOCKET socket = -1;
|
||||||
u_long yes = 1;
|
u_long yes = 1;
|
||||||
@@ -36,7 +37,8 @@ SOCKET plat_netsocket_create(int type)
|
|||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
SOCKET
|
||||||
|
plat_netsocket_create_server(int type, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
SOCKET socket = -1;
|
SOCKET socket = -1;
|
||||||
@@ -55,14 +57,14 @@ SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
|||||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
sock_addr.sin_port = htons(port);
|
sock_addr.sin_port = htons(port);
|
||||||
|
|
||||||
if (bind(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
|
if (bind(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
|
||||||
plat_netsocket_close(socket);
|
plat_netsocket_close(socket);
|
||||||
return (SOCKET)-1;
|
return (SOCKET) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(socket, 5) == SOCKET_ERROR) {
|
if (listen(socket, 5) == SOCKET_ERROR) {
|
||||||
plat_netsocket_close(socket);
|
plat_netsocket_close(socket);
|
||||||
return (SOCKET)-1;
|
return (SOCKET) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioctlsocket(socket, FIONBIO, &yes);
|
ioctlsocket(socket, FIONBIO, &yes);
|
||||||
@@ -70,12 +72,14 @@ SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
|||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plat_netsocket_close(SOCKET socket)
|
void
|
||||||
|
plat_netsocket_close(SOCKET socket)
|
||||||
{
|
{
|
||||||
closesocket((SOCKET)socket);
|
closesocket((SOCKET) socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET plat_netsocket_accept(SOCKET socket)
|
SOCKET
|
||||||
|
plat_netsocket_accept(SOCKET socket)
|
||||||
{
|
{
|
||||||
SOCKET clientsocket = accept(socket, NULL, NULL);
|
SOCKET clientsocket = accept(socket, NULL, NULL);
|
||||||
|
|
||||||
@@ -85,7 +89,8 @@ SOCKET plat_netsocket_accept(SOCKET socket)
|
|||||||
return clientsocket;
|
return clientsocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_connected(SOCKET socket)
|
int
|
||||||
|
plat_netsocket_connected(SOCKET socket)
|
||||||
{
|
{
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
socklen_t len = sizeof(struct sockaddr);
|
socklen_t len = sizeof(struct sockaddr);
|
||||||
@@ -109,7 +114,7 @@ int plat_netsocket_connected(SOCKET socket)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (res >= 1 && FD_ISSET(socket, &exfds)) {
|
if (res >= 1 && FD_ISSET(socket, &exfds)) {
|
||||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||||
pclog("Socket error %d\n", status);
|
pclog("Socket error %d\n", status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -117,7 +122,7 @@ int plat_netsocket_connected(SOCKET socket)
|
|||||||
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||||
|
|
||||||
if (res == SOCKET_ERROR)
|
if (res == SOCKET_ERROR)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -131,7 +136,8 @@ int plat_netsocket_connected(SOCKET socket)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port)
|
int
|
||||||
|
plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
@@ -151,7 +157,7 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = connect(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in));
|
res = connect(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
if (res == SOCKET_ERROR) {
|
if (res == SOCKET_ERROR) {
|
||||||
int error = WSAGetLastError();
|
int error = WSAGetLastError();
|
||||||
@@ -164,9 +170,10 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock)
|
int
|
||||||
|
plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock)
|
||||||
{
|
{
|
||||||
int res = send(socket, (const char*)data, size, 0);
|
int res = send(socket, (const char *) data, size, 0);
|
||||||
|
|
||||||
if (res == SOCKET_ERROR) {
|
if (res == SOCKET_ERROR) {
|
||||||
int error = WSAGetLastError();
|
int error = WSAGetLastError();
|
||||||
@@ -179,9 +186,10 @@ int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int s
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock)
|
int
|
||||||
|
plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock)
|
||||||
{
|
{
|
||||||
int res = recv(socket, (char*)data, size, 0);
|
int res = recv(socket, (char *) data, size, 0);
|
||||||
|
|
||||||
if (res == SOCKET_ERROR) {
|
if (res == SOCKET_ERROR) {
|
||||||
int error = WSAGetLastError();
|
int error = WSAGetLastError();
|
||||||
|
@@ -19,17 +19,14 @@
|
|||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/tcp.h>
|
#include <netinet/tcp.h>
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
SOCKET plat_netsocket_create(int type)
|
SOCKET
|
||||||
|
plat_netsocket_create(int type)
|
||||||
{
|
{
|
||||||
SOCKET fd = -1;
|
SOCKET fd = -1;
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
@@ -42,12 +39,13 @@ SOCKET plat_netsocket_create(int type)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&yes, sizeof(yes));
|
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof(yes));
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
SOCKET
|
||||||
|
plat_netsocket_create_server(int type, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
SOCKET fd = -1;
|
SOCKET fd = -1;
|
||||||
@@ -66,28 +64,30 @@ SOCKET plat_netsocket_create_server(int type, unsigned short port)
|
|||||||
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
sock_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
sock_addr.sin_port = htons(port);
|
sock_addr.sin_port = htons(port);
|
||||||
|
|
||||||
if (bind(fd, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in)) == -1) {
|
if (bind(fd, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in)) == -1) {
|
||||||
plat_netsocket_close(fd);
|
plat_netsocket_close(fd);
|
||||||
return (SOCKET)-1;
|
return (SOCKET) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (listen(fd, 5) == -1) {
|
if (listen(fd, 5) == -1) {
|
||||||
plat_netsocket_close(fd);
|
plat_netsocket_close(fd);
|
||||||
return (SOCKET)-1;
|
return (SOCKET) -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char*)&yes, sizeof(yes));
|
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &yes, sizeof(yes));
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void plat_netsocket_close(SOCKET socket)
|
void
|
||||||
|
plat_netsocket_close(SOCKET socket)
|
||||||
{
|
{
|
||||||
close((SOCKET)socket);
|
close((SOCKET) socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
SOCKET plat_netsocket_accept(SOCKET socket)
|
SOCKET
|
||||||
|
plat_netsocket_accept(SOCKET socket)
|
||||||
{
|
{
|
||||||
SOCKET clientsocket = accept(socket, NULL, NULL);
|
SOCKET clientsocket = accept(socket, NULL, NULL);
|
||||||
|
|
||||||
@@ -97,7 +97,8 @@ SOCKET plat_netsocket_accept(SOCKET socket)
|
|||||||
return clientsocket;
|
return clientsocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_connected(SOCKET socket)
|
int
|
||||||
|
plat_netsocket_connected(SOCKET socket)
|
||||||
{
|
{
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
socklen_t len = sizeof(struct sockaddr);
|
socklen_t len = sizeof(struct sockaddr);
|
||||||
@@ -121,7 +122,7 @@ int plat_netsocket_connected(SOCKET socket)
|
|||||||
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
if (res == 0 || !(res >= 1 && FD_ISSET(socket, &wrfds)))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char*)&status, &optlen);
|
res = getsockopt(socket, SOL_SOCKET, SO_ERROR, (char *) &status, &optlen);
|
||||||
|
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return -1;
|
return -1;
|
||||||
@@ -135,7 +136,8 @@ int plat_netsocket_connected(SOCKET socket)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short port)
|
int
|
||||||
|
plat_netsocket_connect(SOCKET socket, const char *hostname, unsigned short port)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sock_addr;
|
struct sockaddr_in sock_addr;
|
||||||
int res = -1;
|
int res = -1;
|
||||||
@@ -144,7 +146,7 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||||||
sock_addr.sin_addr.s_addr = inet_addr(hostname);
|
sock_addr.sin_addr.s_addr = inet_addr(hostname);
|
||||||
sock_addr.sin_port = htons(port);
|
sock_addr.sin_port = htons(port);
|
||||||
|
|
||||||
if (sock_addr.sin_addr.s_addr == ((in_addr_t)-1) || sock_addr.sin_addr.s_addr == 0) {
|
if (sock_addr.sin_addr.s_addr == ((in_addr_t) -1) || sock_addr.sin_addr.s_addr == 0) {
|
||||||
struct hostent *hp;
|
struct hostent *hp;
|
||||||
|
|
||||||
hp = gethostbyname(hostname);
|
hp = gethostbyname(hostname);
|
||||||
@@ -155,7 +157,7 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = connect(socket, (struct sockaddr *)&sock_addr, sizeof(struct sockaddr_in));
|
res = connect(socket, (struct sockaddr *) &sock_addr, sizeof(struct sockaddr_in));
|
||||||
|
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
int error = errno;
|
int error = errno;
|
||||||
@@ -168,9 +170,10 @@ int plat_netsocket_connect(SOCKET socket, const char* hostname, unsigned short p
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int size, int *wouldblock)
|
int
|
||||||
|
plat_netsocket_send(SOCKET socket, const unsigned char *data, unsigned int size, int *wouldblock)
|
||||||
{
|
{
|
||||||
int res = send(socket, (const char*)data, size, 0);
|
int res = send(socket, (const char *) data, size, 0);
|
||||||
|
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
int error = errno;
|
int error = errno;
|
||||||
@@ -183,9 +186,10 @@ int plat_netsocket_send(SOCKET socket, const unsigned char* data, unsigned int s
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int plat_netsocket_receive(SOCKET socket, unsigned char* data, unsigned int size, int *wouldblock)
|
int
|
||||||
|
plat_netsocket_receive(SOCKET socket, unsigned char *data, unsigned int size, int *wouldblock)
|
||||||
{
|
{
|
||||||
int res = recv(socket, (char*)data, size, 0);
|
int res = recv(socket, (char *) data, size, 0);
|
||||||
|
|
||||||
if (res == -1) {
|
if (res == -1) {
|
||||||
int error = errno;
|
int error = errno;
|
||||||
|
Reference in New Issue
Block a user