Checksum.
This commit is contained in:
parent
fc336c1103
commit
602feb2016
41
phoned/cid.c
41
phoned/cid.c
@ -27,7 +27,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/cid.c,v 1.7 2005/06/21 01:13:26 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/cid.c,v 1.8 2005/06/22 04:01:03 dcp1990 Exp $ */
|
||||||
/* system includes */
|
/* system includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -37,8 +37,9 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
#define BOGUS(pnt, cl, st, orig) if(pnt + cl > orig + st) { \
|
/* ex: BOGUS(p, cpl, i, s, "numb"); */
|
||||||
lprintf(error, "Packet length of %d is bogus (len is %d!)", cl, st); break; }
|
#define BOGUS(pnt, cl, st, orig, part) if(pnt + cl - 1 > orig + st) { \
|
||||||
|
lprintf(error, "%s: Packet length of %d is bogus (len is %d, would be 0x%x when should 0x%x!)", part, cl, st, pnt + cl, orig + st); break; }
|
||||||
int free_cid(cid_t* ctf)
|
int free_cid(cid_t* ctf)
|
||||||
{
|
{
|
||||||
free(ctf->name);
|
free(ctf->name);
|
||||||
@ -51,13 +52,14 @@ cid_t *decode_sdmf(s)
|
|||||||
{
|
{
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
unsigned char dtbuf[2];
|
unsigned char dtbuf[2];
|
||||||
int i = 0, ld;
|
int i = 0, ld, rsz, j, cstotal, checksum;
|
||||||
cid_t *c;
|
cid_t *c;
|
||||||
if(*s != 0x04) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
if(*s != 0x04) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
||||||
c = malloc(sizeof(cid_t));
|
c = malloc(sizeof(cid_t));
|
||||||
memset(c, 0x0, sizeof(cid_t));
|
memset(c, 0x0, sizeof(cid_t));
|
||||||
c->name = strdup("NO NAME");
|
c->name = strdup("NO NAME");
|
||||||
p = s;
|
p = s;
|
||||||
|
rsz = strlen(s);
|
||||||
p++;
|
p++;
|
||||||
ld = *p++;
|
ld = *p++;
|
||||||
i = strlen(p);
|
i = strlen(p);
|
||||||
@ -76,6 +78,14 @@ cid_t *decode_sdmf(s)
|
|||||||
c->minute = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
c->minute = ((*dtbuf - '0') * 10) + (dtbuf[1] - '0');
|
||||||
c->number = malloc(strlen(p) * sizeof(unsigned char));
|
c->number = malloc(strlen(p) * sizeof(unsigned char));
|
||||||
snprintf(c->number, strlen(p), "%s", p);
|
snprintf(c->number, strlen(p), "%s", p);
|
||||||
|
checksum = s[rsz - 1];
|
||||||
|
cstotal = 0;
|
||||||
|
for(j = 0; j < rsz - 1; j++) {
|
||||||
|
cstotal += s[j];
|
||||||
|
}
|
||||||
|
if((cstotal & 0xff) + checksum != 256)
|
||||||
|
lprintf(warn, "decode_sdmf: Warning: Checksum failed! (0x%x real, cs was 0x%x, total %d)",
|
||||||
|
(cstotal & 0xff) + checksum, checksum, cstotal);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,11 +94,13 @@ cid_t *decode_mdmf(s)
|
|||||||
{
|
{
|
||||||
unsigned char *p;
|
unsigned char *p;
|
||||||
unsigned char dtbuf[2];
|
unsigned char dtbuf[2];
|
||||||
int i = 0, j = 0, ld, cpl, checksum;
|
int i = 0, j = 0, ld, cpl, checksum, rsz;
|
||||||
|
int cstotal;
|
||||||
cid_t *c;
|
cid_t *c;
|
||||||
if(*s != 0x80) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
if(*s != 0x80) return NULL; /* 0x04 is SDMF, anything else is garbage */
|
||||||
c = malloc(sizeof(cid_t));
|
c = malloc(sizeof(cid_t));
|
||||||
memset(c, 0x0, sizeof(cid_t));
|
memset(c, 0x0, sizeof(cid_t));
|
||||||
|
rsz = strlen(s);
|
||||||
p = s;
|
p = s;
|
||||||
p++;
|
p++;
|
||||||
ld = *p++;
|
ld = *p++;
|
||||||
@ -98,7 +110,7 @@ cid_t *decode_mdmf(s)
|
|||||||
switch(*p++) { /* data type */
|
switch(*p++) { /* data type */
|
||||||
case 0x01: /* date and time */
|
case 0x01: /* date and time */
|
||||||
cpl = *p++;
|
cpl = *p++;
|
||||||
BOGUS(p, cpl, i, s);
|
BOGUS(p, cpl, i, s, "dtime");
|
||||||
if(cpl != 8) lprintf(warn, "decode_mdmf: Warning: date length != 8 (%d really)", cpl);
|
if(cpl != 8) lprintf(warn, "decode_mdmf: Warning: date length != 8 (%d really)", cpl);
|
||||||
*dtbuf = *p++;
|
*dtbuf = *p++;
|
||||||
dtbuf[1] = *p++;
|
dtbuf[1] = *p++;
|
||||||
@ -116,7 +128,7 @@ cid_t *decode_mdmf(s)
|
|||||||
break;
|
break;
|
||||||
case 0x02: /* number */
|
case 0x02: /* number */
|
||||||
cpl = *p++;
|
cpl = *p++;
|
||||||
BOGUS(p, cpl, i, s);
|
BOGUS(p, cpl, i, s, "numb");
|
||||||
if(cpl != 10) lprintf(info, "decode_mdmf: Info: number length != 10 (%d really)", cpl);
|
if(cpl != 10) lprintf(info, "decode_mdmf: Info: number length != 10 (%d really)", cpl);
|
||||||
c->number = malloc(cpl * sizeof(unsigned char));
|
c->number = malloc(cpl * sizeof(unsigned char));
|
||||||
memset(c->number, 0, cpl * sizeof(unsigned char));
|
memset(c->number, 0, cpl * sizeof(unsigned char));
|
||||||
@ -127,7 +139,7 @@ cid_t *decode_mdmf(s)
|
|||||||
break;
|
break;
|
||||||
case 0x04: /* number not available */
|
case 0x04: /* number not available */
|
||||||
cpl = *p++;
|
cpl = *p++;
|
||||||
BOGUS(p, cpl, i, s);
|
BOGUS(p, cpl, i, s, "nna");
|
||||||
if(cpl < 0x01) {
|
if(cpl < 0x01) {
|
||||||
lprintf(warn, "decode_mdmf: Warning: type 0x04 (no number) len < 1 (%d really)", cpl);
|
lprintf(warn, "decode_mdmf: Warning: type 0x04 (no number) len < 1 (%d really)", cpl);
|
||||||
break;
|
break;
|
||||||
@ -139,7 +151,7 @@ cid_t *decode_mdmf(s)
|
|||||||
break;
|
break;
|
||||||
case 0x07: /* name */
|
case 0x07: /* name */
|
||||||
cpl = *p++;
|
cpl = *p++;
|
||||||
BOGUS(p, cpl, i, s);
|
BOGUS(p, cpl, i, s, "name");
|
||||||
c->name = malloc(cpl * sizeof(unsigned char));
|
c->name = malloc(cpl * sizeof(unsigned char));
|
||||||
memset(c->name, 0, cpl * sizeof(unsigned char));
|
memset(c->name, 0, cpl * sizeof(unsigned char));
|
||||||
for(j = 0; j < cpl && p != 0; j++) {
|
for(j = 0; j < cpl && p != 0; j++) {
|
||||||
@ -156,7 +168,7 @@ cid_t *decode_mdmf(s)
|
|||||||
break;
|
break;
|
||||||
case 0x08: /* name not available */
|
case 0x08: /* name not available */
|
||||||
cpl = *p++;
|
cpl = *p++;
|
||||||
BOGUS(p, cpl, i, s);
|
BOGUS(p, cpl, i, s, "nana");
|
||||||
if(cpl < 0x01) {
|
if(cpl < 0x01) {
|
||||||
lprintf(warn, "decode_mdmf: Warning: type 0x08 (no name) len < 1 (%d really)", cpl);
|
lprintf(warn, "decode_mdmf: Warning: type 0x08 (no name) len < 1 (%d really)", cpl);
|
||||||
break;
|
break;
|
||||||
@ -174,7 +186,14 @@ cid_t *decode_mdmf(s)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lprintf(info, "Finished mdmf (%d/%d %d:%d %s -- %s)", c->month, c->day, c->hour, c->minute, c->name, c->number);
|
checksum = s[rsz - 1];
|
||||||
|
cstotal = 0;
|
||||||
|
for(j = 0; j < rsz - 1; j++) {
|
||||||
|
cstotal += s[j];
|
||||||
|
}
|
||||||
|
if((cstotal & 0xff) + checksum != 256)
|
||||||
|
lprintf(warn, "decode_mdmf: Warning: Checksum failed! (0x%x real, cs was 0x%x, total %d)",
|
||||||
|
(cstotal & 0xff) + checksum, checksum, cstotal);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ void modem_hread(char* cbuf)
|
|||||||
pthread_mutex_lock(&buffermx);
|
pthread_mutex_lock(&buffermx);
|
||||||
if(cou < sizeof(buffer) - 2)
|
if(cou < sizeof(buffer) - 2)
|
||||||
buffer[cou] = cbuf[0];
|
buffer[cou] = cbuf[0];
|
||||||
if(buffer[0] == '8' && buffer[1] == '0')
|
if((buffer[0] == '8' && buffer[1] == '0') || (buffer[0] == '0' && buffer[1] == '4'))
|
||||||
doing_cid = 1;
|
doing_cid = 1;
|
||||||
if(cbuf[0] == '\n') {
|
if(cbuf[0] == '\n') {
|
||||||
/* lprintf(debug, "Modem said %s", buffer); */
|
/* lprintf(debug, "Modem said %s", buffer); */
|
||||||
|
@ -28,7 +28,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* $Amigan: phoned/phoned/remote.c,v 1.10 2005/06/21 01:13:26 dcp1990 Exp $ */
|
/* $Amigan: phoned/phoned/remote.c,v 1.11 2005/06/22 04:01:03 dcp1990 Exp $ */
|
||||||
/* system includes */
|
/* system includes */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -262,7 +262,6 @@ char *parse_command(cmd, cont, s)
|
|||||||
} else if(CHK("tparse")) {
|
} else if(CHK("tparse")) {
|
||||||
cid_t* rc;
|
cid_t* rc;
|
||||||
rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");
|
rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");
|
||||||
lprintf(info, "nam=%s;month=%d\n", rc->name, rc->month);
|
|
||||||
cid_log(rc);
|
cid_log(rc);
|
||||||
cid_notify(rc);
|
cid_notify(rc);
|
||||||
free(rc);
|
free(rc);
|
||||||
|
Loading…
Reference in New Issue
Block a user