mirror of git://git.sysmocom.de/ofono
First round of coding style updates for GSM 07.10 implementation
This commit is contained in:
parent
ec69d1abd0
commit
f49e1f9f4f
|
@ -30,6 +30,24 @@
|
|||
|
||||
#include "gsm0710_p.h"
|
||||
|
||||
/* Frame types and subtypes */
|
||||
#define GSM0710_OPEN_CHANNEL 0x3F
|
||||
#define GSM0710_CLOSE_CHANNEL 0x53
|
||||
#define GSM0710_DATA 0xEF
|
||||
#define GSM0710_DATA_ALT 0x03
|
||||
#define GSM0710_STATUS_SET 0xE3
|
||||
#define GSM0710_STATUS_ACK 0xE1
|
||||
#define GSM0710_TERMINATE_BYTE1 0xC3
|
||||
#define GSM0710_TERMINATE_BYTE2 0x01
|
||||
|
||||
/* Status flags */
|
||||
#define GSM0710_FC 0x02
|
||||
#define GSM0710_DTR 0x04
|
||||
#define GSM0710_DSR 0x04
|
||||
#define GSM0710_RTS 0x08
|
||||
#define GSM0710_CTS 0x08
|
||||
#define GSM0710_DCD 0x80
|
||||
|
||||
/* Initialize a GSM 07.10 context, in preparation for startup */
|
||||
void gsm0710_initialize(struct gsm0710_context *ctx)
|
||||
{
|
||||
|
@ -219,19 +237,33 @@ int gsm0710_startup(struct gsm0710_context *ctx, int send_cmux)
|
|||
if (send_cmux) {
|
||||
int speed;
|
||||
switch (ctx->port_speed) {
|
||||
case 9600: speed = 1; break;
|
||||
case 19200: speed = 2; break;
|
||||
case 38400: speed = 3; break;
|
||||
case 57600: speed = 4; break;
|
||||
case 115200: speed = 5; break;
|
||||
case 230400: speed = 6; break;
|
||||
default: speed = 5; break;
|
||||
case 9600:
|
||||
speed = 1;
|
||||
break;
|
||||
case 19200:
|
||||
speed = 2;
|
||||
break;
|
||||
case 38400:
|
||||
speed = 3;
|
||||
break;
|
||||
case 57600:
|
||||
speed = 4;
|
||||
break;
|
||||
case 115200:
|
||||
speed = 5;
|
||||
break;
|
||||
case 230400:
|
||||
speed = 6;
|
||||
break;
|
||||
default:
|
||||
speed = 5;
|
||||
break;
|
||||
}
|
||||
sprintf(command, "AT+CMUX=%d,0,%d,%d",
|
||||
ctx->mode, speed, ctx->frame_size);
|
||||
if (!ctx->at_command || !ctx->at_command(ctx, command)) {
|
||||
gsm0710_debug
|
||||
(ctx, "could not initialize multiplexing with AT+CMUX");
|
||||
gsm0710_debug(ctx,
|
||||
"could not initialize multiplexing with AT+CMUX");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -244,9 +276,11 @@ int gsm0710_startup(struct gsm0710_context *ctx, int send_cmux)
|
|||
layers to abort pending AT commands */
|
||||
for (channel = 1; channel <= GSM0710_MAX_CHANNELS; ++channel) {
|
||||
if (is_channel_used(ctx, channel)) {
|
||||
gsm0710_write_frame(ctx, channel, GSM0710_OPEN_CHANNEL, 0, 0);
|
||||
gsm0710_write_frame(ctx, channel,
|
||||
GSM0710_OPEN_CHANNEL, 0, 0);
|
||||
if (ctx->deliver_data)
|
||||
ctx->deliver_data(ctx, channel, "\r\nERROR\r\n", 9);
|
||||
ctx->deliver_data(ctx, channel,
|
||||
"\r\nERROR\r\n", 9);
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
|
@ -255,13 +289,14 @@ int gsm0710_startup(struct gsm0710_context *ctx, int send_cmux)
|
|||
/* Shut down the GSM 07.10 session, closing all channels */
|
||||
void gsm0710_shutdown(struct gsm0710_context *ctx)
|
||||
{
|
||||
static const unsigned char terminate[2] =
|
||||
{GSM0710_TERMINATE_BYTE1, GSM0710_TERMINATE_BYTE2};
|
||||
static const unsigned char terminate[2] = { GSM0710_TERMINATE_BYTE1,
|
||||
GSM0710_TERMINATE_BYTE2 };
|
||||
if (!ctx->server) {
|
||||
int channel;
|
||||
for (channel = 1; channel <= GSM0710_MAX_CHANNELS; ++channel) {
|
||||
if (is_channel_used(ctx, channel)) {
|
||||
gsm0710_write_frame(ctx, channel, GSM0710_CLOSE_CHANNEL, 0, 0);
|
||||
gsm0710_write_frame(ctx, channel,
|
||||
GSM0710_CLOSE_CHANNEL, 0, 0);
|
||||
}
|
||||
}
|
||||
gsm0710_write_frame(ctx, 0, GSM0710_DATA, terminate, 2);
|
||||
|
@ -321,7 +356,8 @@ static int gsm0710_packet( struct gsm0710_context *ctx, int channel, int type,
|
|||
} else if (channel == 0) {
|
||||
/* An embedded command or response on channel 0 */
|
||||
if (len >= 2 && data[0] == GSM0710_STATUS_SET) {
|
||||
return gsm0710_packet(ctx, channel, GSM0710_STATUS_ACK,
|
||||
return gsm0710_packet(ctx, channel,
|
||||
GSM0710_STATUS_ACK,
|
||||
data + 2, len - 2);
|
||||
} else if (len >= 2 && data[0] == 0xC3 && ctx->server) {
|
||||
/* Incoming terminate request on server side */
|
||||
|
@ -331,7 +367,8 @@ static int gsm0710_packet( struct gsm0710_context *ctx, int channel, int type,
|
|||
ctx->close_channel(ctx, channel);
|
||||
}
|
||||
}
|
||||
memset(ctx->used_channels, 0, sizeof(ctx->used_channels));
|
||||
memset(ctx->used_channels, 0,
|
||||
sizeof(ctx->used_channels));
|
||||
if (ctx->terminate)
|
||||
ctx->terminate(ctx);
|
||||
return 0;
|
||||
|
@ -340,7 +377,8 @@ static int gsm0710_packet( struct gsm0710_context *ctx, int channel, int type,
|
|||
unsigned char *resp = alloca(len);
|
||||
memcpy(resp, data, len);
|
||||
resp[0] = 0x41; /* Clear the C/R bit in the response */
|
||||
gsm0710_write_frame(ctx, 0, GSM0710_DATA, resp, len);
|
||||
gsm0710_write_frame(ctx, 0, GSM0710_DATA,
|
||||
resp, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -355,12 +393,14 @@ static int gsm0710_packet( struct gsm0710_context *ctx, int channel, int type,
|
|||
if (channel >= 1 && channel <= GSM0710_MAX_CHANNELS &&
|
||||
is_channel_used(ctx, channel)) {
|
||||
if (ctx->deliver_status)
|
||||
ctx->deliver_status(ctx, channel, data[1] & 0xFF);
|
||||
ctx->deliver_status(ctx, channel,
|
||||
data[1] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the response to the status change request to ACK it */
|
||||
gsm0710_debug(ctx, "received status line signal, sending response");
|
||||
gsm0710_debug(ctx,
|
||||
"received status line signal, sending response");
|
||||
if (len > 31)
|
||||
len = 31;
|
||||
resp[0] = GSM0710_STATUS_ACK;
|
||||
|
@ -457,10 +497,10 @@ void gsm0710_ready_read(struct gsm0710_context *ctx)
|
|||
break;
|
||||
|
||||
/* Verify the packet header checksum */
|
||||
if (((gsm0710_compute_crc(ctx->buffer + posn + 1, header_size) ^
|
||||
ctx->buffer[posn + len + header_size + 1]) & 0xFF)
|
||||
!= 0) {
|
||||
gsm0710_debug(ctx, "*** GSM 07.10 checksum check failed ***");
|
||||
if (((gsm0710_compute_crc(ctx->buffer + posn + 1,
|
||||
header_size) ^ ctx->buffer[posn + len + header_size + 1]) & 0xFF) != 0) {
|
||||
gsm0710_debug(ctx,
|
||||
"*** GSM 07.10 checksum check failed ***");
|
||||
posn += len + header_size + 2;
|
||||
continue;
|
||||
}
|
||||
|
@ -520,12 +560,14 @@ void gsm0710_ready_read(struct gsm0710_context *ctx)
|
|||
if (posn2 >= 3) {
|
||||
if (((gsm0710_compute_crc(ctx->buffer, 2) ^
|
||||
ctx->buffer[posn2 - 1]) & 0xFF) != 0) {
|
||||
gsm0710_debug(ctx, "*** GSM 07.10 advanced checksum "
|
||||
gsm0710_debug(ctx,
|
||||
"*** GSM 07.10 advanced checksum "
|
||||
"check failed ***");
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
gsm0710_debug(ctx, "*** GSM 07.10 advanced packet "
|
||||
gsm0710_debug(ctx,
|
||||
"*** GSM 07.10 advanced packet "
|
||||
"is too small ***");
|
||||
continue;
|
||||
}
|
||||
|
@ -545,7 +587,8 @@ void gsm0710_ready_read(struct gsm0710_context *ctx)
|
|||
}
|
||||
}
|
||||
if (posn < ctx->buffer_used) {
|
||||
memmove( ctx->buffer, ctx->buffer + posn, ctx->buffer_used - posn );
|
||||
memmove(ctx->buffer, ctx->buffer + posn,
|
||||
ctx->buffer_used - posn);
|
||||
ctx->buffer_used -= posn;
|
||||
} else {
|
||||
ctx->buffer_used = 0;
|
||||
|
|
|
@ -34,24 +34,6 @@ extern "C" {
|
|||
#define GSM0710_MODE_BASIC 0
|
||||
#define GSM0710_MODE_ADVANCED 1
|
||||
|
||||
/* Frame types and subtypes */
|
||||
#define GSM0710_OPEN_CHANNEL 0x3F
|
||||
#define GSM0710_CLOSE_CHANNEL 0x53
|
||||
#define GSM0710_DATA 0xEF
|
||||
#define GSM0710_DATA_ALT 0x03
|
||||
#define GSM0710_STATUS_SET 0xE3
|
||||
#define GSM0710_STATUS_ACK 0xE1
|
||||
#define GSM0710_TERMINATE_BYTE1 0xC3
|
||||
#define GSM0710_TERMINATE_BYTE2 0x01
|
||||
|
||||
/* Status flags */
|
||||
#define GSM0710_FC 0x02
|
||||
#define GSM0710_DTR 0x04
|
||||
#define GSM0710_DSR 0x04
|
||||
#define GSM0710_RTS 0x08
|
||||
#define GSM0710_CTS 0x08
|
||||
#define GSM0710_DCD 0x80
|
||||
|
||||
struct gsm0710_context
|
||||
{
|
||||
/* GSM 07.10 implementation details */
|
||||
|
|
Loading…
Reference in New Issue