Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 132 lines (116 sloc) 2.878 kb
2652077 Joshua Hill copied over payload module from latest greenpois0n
posixninja authored
1 /**
2 * GreenPois0n Cynanide - radio.c
3 * Copyright (C) 2010 Chronic-Dev Team
4 * Copyright (C) 2010 Joshua Hill
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23
24 #include "uart.h"
25 #include "radio.h"
26 #include "commands.h"
27
28 static Bool gRadioReadInit = FALSE;
29
30 int radio_init() {
31 srand(1);
32 if(uart_read && uart_write) {
33 cmd_add("radio", &radio_cmd, "send AT commands to baseband radio");
34 }
35 return 0;
36 }
37
38 int radio_cmd(int argc, CmdArg* argv) {
39 int i = 0;
40 int ret = 0;
41 char* data = NULL;
42
43 if(gRadioReadInit == FALSE) {
44 //TaskDescriptor* radio_reader_task = task_create("radio_reader", &radio_reader, 0, 0x2000);
45 //task_start(radio_reader_task);
46 gRadioReadInit = TRUE;
47 }
48
49 if(argc == 1) {
50 radio_send_random();
51 return 0;
52 }
53
54 data = malloc(0x100);
55 memset(data, '\0', 0x100);
56 for(i = 1; i < argc; i++) {
57 if(i > 2) {
58 strncat(data, " ", 0x100);
59 }
60 strncat(data, argv[i].string, 0x100);
61 }
62 ret = radio_write(data);
63
64 free(data);
65 return ret;
66 }
67
68 int radio_write(char* command) {
69 int size = 0;
70 char data[0x100];
71 memset(data, '\0', 0x100);
72 strncpy(data, command, 0x100);
73 strncat(data, "\r", 0x100);
74 size = strlen(data);
75 uart_write(1, data, size);
76 return size;
77 }
78
79 int radio_read(char* buffer, unsigned int size) {
80 return size;
81 }
82
83 void radio_set_debug() {
84 radio_write("at+cmee=1");
85 radio_write("at+creg=1");
86 }
87
88 int radio_find_commands() {
89 srand(1);
90 int i = 0;
91 char string[8];
92 char command[32];
93 memset(string, '\0', 8);
94 while(1) {
95 memset(command, '\0', 32);
96 strcpy(command, "at+");
97 for(i = 0; i < 4; i++) {
98 string[0] = (char) (rand() % 26) + 0x61;
99 strncat(command, string, 32);
100 }
101 strncat(command, "=?", 32);
102 radio_write(command);
103 //radio_read(response);
104 }
105 return 0;
106 }
107
108 int radio_send_random() {
109 int i = 0;
110 char string[8];
111 char command[32];
112 memset(string, '\0', 8);
113 memset(command, '\0', 32);
114 strcpy(command, "at+");
115 for(i = 0; i < 4; i++) {
116 string[0] = (char) (rand() % 26) + 0x61;
117 strncat(command, string, 32);
118 }
119 strncat(command, "=?", 32);
120 printf("Sending \"%s\"\n", command);
121 radio_write(command);
122 return 0;
123 }
124
125 void radio_reader(void* arg) {
126 char byte;
127 while(1) {
128 uart_read(1, &byte, 1, 1);
129 printf("%c", byte);
130 }
131 }
Something went wrong with that request. Please try again.