Skip to content

Commit

Permalink
Merge branch 'guhl'
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzt committed Dec 15, 2010
2 parents 7346deb + 4068902 commit a6d4400
Show file tree
Hide file tree
Showing 16 changed files with 2,808 additions and 21 deletions.
20 changes: 20 additions & 0 deletions guhl/gfree_verify/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
VERSION = 0.01
CC = /usr/bin/gcc
CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
LDFLAGS = -lm
RM = rm -f

TRG = gfree_verify
OBJ = soff_verify.o gfree_verify.o

all: $(OBJ)
$(CC) $(CFLAGS) -o $(TRG) $(OBJ) $(LDFLAGS)

%.o: %.c
$(CC) $(CFLAGS) -c $<

clean:
$(RM) *.o
$(RM) *.d
$(RM) gfree_verify

41 changes: 41 additions & 0 deletions guhl/gfree_verify/gfree_verify.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright (C) 2010 Guhl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "soff_verify.h"

#define VERSION_A 0
#define VERSION_B 01

int main() {
if (verify_init_device()!=0){
fprintf( stderr, "Error: verify could not initialize device!");
exit (-1);
}
if (verify_init_modem()!=0){
fprintf( stderr, "Error: verify could not initialize radio!");
exit (-1);
}
verify_set_verbose();
verify_cid();
verify_secu_flag();
verify_simlock();
verify_close_device();
exit (0);
}
178 changes: 178 additions & 0 deletions guhl/gfree_verify/soff_verify.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
Copyright (C) 2010 Guhl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "soff_verify.h"

int verify_init_device(){
fd_radio = 0;
fd_radio = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd_radio <0) {
fprintf( stderr, "Error: could not open modem device: %s\n",MODEMDEVICE);
return -1;
}
tcgetattr(fd_radio,&oldtio); // save current serial port settings
memset(&newtio, 0x00, sizeof(newtio)); // clear struct for new port settings

//get the current options
tcgetattr(fd_radio, &newtio);

// set raw input, 1 second timeout
newtio.c_cflag |= (CLOCAL | CREAD);
newtio.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG );
newtio.c_oflag &= ~OPOST;
newtio.c_cc[VMIN] = 0;
newtio.c_cc[VTIME] = 10;

// clean the modem line and activate the settings for the port
tcflush(fd_radio, TCIFLUSH);
tcsetattr(fd_radio,TCSANOW,&newtio);

return 0;
}

int verify_init_modem() {
char buffer[255]; // Input buffer
char *bufptr; // Current char in buffer
int nbytes; // Number of bytes read
int tries; // Number of tries so far

for (tries = 0; tries < 3; tries ++) {
// send an AT command followed by a CR
if (write(fd_radio, "AT\r", 3) < 3)
continue;
// read characters into our string buffer until we get a CR or NL
bufptr = buffer;
while ((nbytes = read(fd_radio, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) {
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
// nul terminate the string and see if we got an OK response */
*bufptr = '\0';
if ((strncmp(buffer, "0", 1) == 0) || (strncmp(buffer, "\r\nOK", 4) == 0))
return (0);
}
return (-1);
}

int verify_set_verbose() {
char buffer[255]; // Input buffer
char *bufptr; // Current char in buffer
int nbytes; // Number of bytes read
int tries; // Number of tries so far

for (tries = 0; tries < 3; tries ++) {
// send an ATV1 command followed by a CR
if (write(fd_radio, "ATV1\r", 5) < 5)
continue;
// read characters into our string buffer until we get a CR or NL
bufptr = buffer;
while ((nbytes = read(fd_radio, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) {
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
// nul terminate the string and see if we got an OK response */
*bufptr = '\0';
if (strncmp(buffer, "\r\nOK", 4) == 0)
return (0);
}
return (-1);
}

int verify_secu_flag() {
char buffer[255]; // Input buffer
char *bufptr; // Current char in buffer
int nbytes; // Number of bytes read
int tries; // Number of tries so far

for (tries = 0; tries < 3; tries ++) {
// send an ATV1 command followed by a CR
if (write(fd_radio, "AT@SIMLOCK?AA\r", 15) < 15)
continue;
// read characters into our string buffer until we get a CR or NL
bufptr = buffer;
while ((nbytes = read(fd_radio, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) {
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
// nul terminate the string and see if we got an OK response */
*bufptr = '\0';
fprintf( stdout, "gfree verify_secu_flag returned: %s\n",buffer);
if (strncmp(buffer, "\r\n@secu_flag: 0", 15) == 0)
return (0);
}
return (-1);
}

void verify_cid() {
char buffer[255]; // Input buffer
char *bufptr; // Current char in buffer
int nbytes; // Number of bytes read
int tries; // Number of tries so far

for (tries = 0; tries < 3; tries ++) {
// send an ATV1 command followed by a CR
if (write(fd_radio, "AT@CID?\r", 8) < 8)
continue;
// read characters into our string buffer until we get a CR or NL
bufptr = buffer;
while ((nbytes = read(fd_radio, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) {
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
// nul terminate the string and see if we got an OK response */
*bufptr = '\0';
fprintf( stdout, "gfree verify_cid returned: %s\n",buffer);
return;
}
}

int verify_simlock() {
char buffer[255]; // Input buffer
char *bufptr; // Current char in buffer
int nbytes; // Number of bytes read
int tries; // Number of tries so far

for (tries = 0; tries < 3; tries ++) {
// send an ATV1 command followed by a CR
if (write(fd_radio, "AT@SIMLOCK?40\r", 15) < 15)
continue;
// read characters into our string buffer until we get a CR or NL
bufptr = buffer;
while ((nbytes = read(fd_radio, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0) {
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
// nul terminate the string and see if we got an OK response */
*bufptr = '\0';
fprintf( stdout, "gfree verify_simlock returned: %s\n",buffer);
if (strncmp(buffer, "\r\n@SIMLOCK= 00", 14) == 0)
return (0);
}
return (-1);
}

int verify_close_device() {
// restore the old port settings
tcsetattr(fd_radio,TCSANOW,&oldtio);
close(fd_radio);
return 0;
}
45 changes: 45 additions & 0 deletions guhl/gfree_verify/soff_verify.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright (C) 2010 Guhl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SOFF_VERIFY_H_
#define SOFF_VERIFY_H_

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define MODEMDEVICE "/dev/smd0"
#define BAUDRATE B38400

int fd_radio;
struct termios oldtio,newtio;

char *squeeze(char *str);
int verify_init_device();
int verify_init_modem();
int verify_set_verbose();
int verify_secu_flag();
void verify_cid();
int verify_simlock();
int verify_close_device();

#endif /* SOFF_VERIFY_H_ */
20 changes: 20 additions & 0 deletions guhl/p7_soff/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
VERSION = 0.02
CC = /usr/bin/gcc
CFLAGS = -Wall -g -D_REENTRANT -DVERSION=\"$(VERSION)\"
LDFLAGS = -lm
RM = rm -f

TRG = p7_s-off
OBJ = gopt.o soff_verify.o p7_s-off.o

all: $(OBJ)
$(CC) $(CFLAGS) -o $(TRG) $(OBJ) $(LDFLAGS)

%.o: %.c
$(CC) $(CFLAGS) -c $<

clean:
$(RM) *.o
$(RM) *.d
$(RM) p7_s-off

Loading

0 comments on commit a6d4400

Please sign in to comment.