Permalink
Browse files

initial

  • Loading branch information...
1 parent 7aa1ade commit d4979e9a0c9f862880643189b0ac631f6f27a492 @pod2g committed Aug 17, 2012
View
@@ -0,0 +1,12 @@
+.DS_Store
+*.swp
+*~.nib
+
+build/
+
+*.pbxuser
+*.perspective
+*.perspectivev3
+*.mode1v3
+*.mode2v3
+xcuserdata
View
@@ -1,4 +0,0 @@
-sendrawpdu
-==========
-
-CLI tool to send raw SMS PDU data to the iPhone 4 baseband
@@ -0,0 +1,17 @@
+Package: pod2g.sendrawpdu
+Name: sendrawpdu
+Version: 0.1-1
+Description:
+Section: System
+Depends: firmware (>= 5.0)
+Conflicts:
+Replaces:
+Priority: optional
+Architecture: iphoneos-arm
+Author: pod2g
+dev:
+Homepage:
+Depiction:
+Maintainer:
+Icon:
+
@@ -0,0 +1,10 @@
+
+The control file in the same directory as this file is the Debian control file that is needed
+to build the project's Debian package that's used by APT repositories like Cydia.
+
+For more on...
+ Debian packages, see http://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html.
+ Debian control files, see http://www.debian.org/doc/debian-policy/ch-controlfields.html.
+ Cydia packages, see http://www.saurik.com/id/7.
+
+Note: This file (control.txt) was created only to provide an explaination about the Debian control file. This file can now be deleted.
@@ -0,0 +1,4 @@
+
+This file was created only to help build the project's group structure, and it can now be deleted.
+
+Why 0xdeadfa11? See http://developer.apple.com/library/ios/#technotes/tn2151/_index.html.
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>BugFix</key>
+ <string></string>
+ <key>Major</key>
+ <string>1</string>
+ <key>Minor</key>
+ <string>0</string>
+ <key>PackageRevision</key>
+ <string>1</string>
+ <key>Stage</key>
+ <string></string>
+</dict>
+</plist>
View
@@ -0,0 +1,145 @@
+/*
+
+ sendrawpdu (c) 2012 pod2g
+
+ Command line tool, usage: sendrawpdu <PDU data in hex>
+
+ - Code based on iphone-elite's sendmodem ( http://code.google.com/p/iphone-elite/wiki/sendmodem )
+ - Just few modifications for SMS sending and iPhone 4 compatibility.
+
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <termios.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/ioctl.h>
+
+#define BUFSIZE (65536+100)
+unsigned char readbuf[BUFSIZE];
+
+static struct termios term;
+static struct termios gOriginalTTYAttrs;
+
+void sendCmd(int fd, void *buf, size_t size);
+void sendStrCmd(int fd, char *buf);
+int readResp(int fd);
+int initConn(int speed);
+void closeConn(int fd);
+void sendAt(int fd);
+void at(int fd);
+
+void sendCmd(int fd, void *buf, size_t size) {
+ if(write(fd, buf, size) == -1) {
+ fprintf(stderr, "sendCmd error. %s\n", strerror(errno));
+ exit(1);
+ }
+}
+
+void sendStrCmd(int fd, char *buf) {
+ sendCmd(fd, buf, strlen(buf));
+}
+
+int readResp(int fd) {
+ int len = 0;
+ struct timeval timeout;
+ int nfds = fd + 1;
+ fd_set readfds;
+ int select_ret;
+
+ FD_ZERO(&readfds);
+ FD_SET(fd, &readfds);
+
+ // Wait a second
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 500000;
+
+ while ((select_ret = select(nfds, &readfds, NULL, NULL, &timeout)) > 0) {
+ len += read(fd, readbuf + len, BUFSIZE - len);
+ FD_ZERO(&readfds);
+ FD_SET(fd, &readfds);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 500000;
+ }
+ if (len > 0) {
+ }
+ readbuf[len] = 0;
+ fprintf(stderr,"%s",readbuf);
+ return len;
+}
+
+int initConn(int speed) {
+ int fd = open("/dev/dlci.spi-baseband.extra_0", O_RDWR | O_NOCTTY);
+
+ if(fd == -1) {
+ fprintf(stderr, "%i(%s)\n", errno, strerror(errno));
+ exit(1);
+ }
+
+ ioctl(fd, TIOCEXCL);
+ fcntl(fd, F_SETFL, 0);
+
+ tcgetattr(fd, &term);
+ gOriginalTTYAttrs = term;
+
+ cfmakeraw(&term);
+ cfsetspeed(&term, speed);
+ term.c_cflag = CS8 | CLOCAL | CREAD;
+ term.c_iflag = 0;
+ term.c_oflag = 0;
+ term.c_lflag = 0;
+ term.c_cc[VMIN] = 0;
+ term.c_cc[VTIME] = 0;
+ tcsetattr(fd, TCSANOW, &term);
+
+ return fd;
+}
+
+void closeConn(int fd) {
+ tcdrain(fd);
+ tcsetattr(fd, TCSANOW, &gOriginalTTYAttrs);
+ close(fd);
+}
+
+void sendAt(int fd) {
+ char cmd[5];
+ sprintf(cmd,"AT\r");
+ sendCmd(fd, cmd, strlen(cmd));
+}
+
+void at(int fd) {
+ sendAt(fd);
+ for (;;) {
+ if(readResp(fd) != 0) {
+ if(strstr((const char *)readbuf,"OK") != NULL) {
+ break;
+ }
+ }
+ sendAt(fd);
+ }
+}
+
+int main(int argc, char **argv) {
+ int fd;
+ char cmd[1024];
+ if(argc < 2) {
+ fprintf(stderr,"usage: %s <pdu data>\n",argv[0]);
+ exit(1);
+ }
+ fd = initConn(115200);
+ at(fd);
+ sendStrCmd(fd, "AT+CMGF=0\r");
+ readResp(fd);
+ sprintf(cmd, "AT+CMGS=%ld\r", strlen(argv[1])/2 - 1);
+ sendStrCmd(fd, cmd);
+ readResp(fd);
+ sprintf(cmd,"%s\032",argv[1]);
+ sendStrCmd(fd, cmd);
+ readResp(fd);
+ closeConn(fd);
+ return 0;
+}

0 comments on commit d4979e9

Please sign in to comment.