Holger Hans Peter Freyther | c88a4fb | 2013-01-20 20:16:30 +0100 | [diff] [blame^] | 1 | From bde45e2f168597c8f4b2bb0599d58125fd24deb6 Mon Sep 17 00:00:00 2001 |
| 2 | From: Holger Hans Peter Freyther <zecke@selfish.org> |
| 3 | Date: Wed, 13 Jun 2012 11:17:33 +0200 |
| 4 | Subject: [PATCH] cell_log: Use the RF-Lock handling to unlock the GSM network |
| 5 | |
| 6 | This is missing the reason of why and when something is unlocked. |
| 7 | --- |
| 8 | src/util/cell_log.c | 65 ++++++++++++++++++++++++++++++++++++++++++--------- |
| 9 | 1 file changed, 54 insertions(+), 11 deletions(-) |
| 10 | |
| 11 | diff --git a/src/util/cell_log.c b/src/util/cell_log.c |
| 12 | index 59d8942..7a280aa 100644 |
| 13 | --- a/src/util/cell_log.c |
| 14 | +++ b/src/util/cell_log.c |
| 15 | @@ -27,10 +27,14 @@ |
| 16 | #include <fcntl.h> |
| 17 | #include <time.h> |
| 18 | #include <syslog.h> |
| 19 | +#include <stdint.h> |
| 20 | |
| 21 | #include <sys/types.h> |
| 22 | +#include <sys/socket.h> |
| 23 | #include <sys/stat.h> |
| 24 | |
| 25 | +#include <netinet/in.h> |
| 26 | + |
| 27 | #include <libgsmd/libgsmd.h> |
| 28 | #include <libgsmd/voicecall.h> |
| 29 | #include <libgsmd/misc.h> |
| 30 | @@ -58,31 +62,70 @@ static int pending_responses = 0; |
| 31 | #define MIN_NO_NET_SECS 60 |
| 32 | #define OUR_MCC 901 |
| 33 | #define OUR_MNC 99 |
| 34 | -#define LOCK_PATH "/var/lock/bts_rf_lock" |
| 35 | |
| 36 | static time_t last_network_seen; |
| 37 | unsigned int rf_lock_active = 0; |
| 38 | |
| 39 | static void bts_rf_lock(int on) |
| 40 | { |
| 41 | - int fd; |
| 42 | + int fd, rc; |
| 43 | + |
| 44 | + static const uint8_t rf_lock[] = { |
| 45 | + 0x00, 0x23, 0xEE, 0x00, 0x53, 0x45, 0x54, 0x20, |
| 46 | + 0x31, 0x20, 0x6E, 0x65, 0x74, 0x2E, 0x72, 0x66, |
| 47 | + 0x5F, 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x67, 0x73, |
| 48 | + 0x6D, 0x2C, 0x6C, 0x6F, 0x63, 0x6B, 0x2C, 0x6E, |
| 49 | + 0x2F, 0x61, 0x2C, 0x6E, 0x2F, 0x61, |
| 50 | + }; |
| 51 | + |
| 52 | + static const uint8_t rf_unlock[] = { |
| 53 | + 0x00, 0x25, 0xEE, 0x00, 0x53, 0x45, 0x54, 0x20, |
| 54 | + 0x31, 0x20, 0x6E, 0x65, 0x74, 0x2E, 0x72, 0x66, |
| 55 | + 0x5F, 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x67, 0x73, |
| 56 | + 0x6D, 0x2C, 0x75, 0x6E, 0x6C, 0x6F, 0x63, 0x6B, |
| 57 | + 0x2C, 0x6E, 0x2F, 0x61, 0x2C, 0x6E, 0x2F, 0x61, |
| 58 | + }; |
| 59 | |
| 60 | /* only print message on status change */ |
| 61 | if (rf_lock_active != on) |
| 62 | syslog(LOG_NOTICE, "RF_LOCK: %sabling lock\n", on ? "En" : "Dis"); |
| 63 | |
| 64 | - /* for safety, always update the actual file on disk */ |
| 65 | + fd = socket(AF_INET, SOCK_STREAM, 0); |
| 66 | + if (fd == -1) { |
| 67 | + syslog(LOG_ERR, "RF_LOCK: socket creation failed: %d\n", errno); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + struct sockaddr_in addr; |
| 72 | + memset(&addr, 0, sizeof(addr)); |
| 73 | + addr.sin_family = AF_INET; |
| 74 | + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); |
| 75 | + addr.sin_port = htons(4249); |
| 76 | + rc = connect(fd, (struct sockaddr *) &addr, sizeof(addr)); |
| 77 | + if (rc != 0) { |
| 78 | + syslog(LOG_ERR, "RF_Lock: socket connect failed: %d\n", errno); |
| 79 | + close(fd); |
| 80 | + return; |
| 81 | + } |
| 82 | + |
| 83 | if (on == 1) { |
| 84 | - struct stat st; |
| 85 | - if (stat(LOCK_PATH, &st) != 0) { |
| 86 | - fd = open(LOCK_PATH, O_WRONLY|O_CREAT, 0664); |
| 87 | - if (fd >= 0) |
| 88 | - close(fd); |
| 89 | - } |
| 90 | - } else |
| 91 | - unlink(LOCK_PATH); |
| 92 | + rc = write(fd, rf_lock, sizeof(rf_lock)); |
| 93 | + if (rc != sizeof(rf_lock)) |
| 94 | + goto error; |
| 95 | + } else { |
| 96 | + rc = write(fd, rf_unlock, sizeof(rf_unlock)); |
| 97 | + if (rc != sizeof(rf_unlock)) |
| 98 | + goto error; |
| 99 | + } |
| 100 | |
| 101 | + close(fd); |
| 102 | rf_lock_active = on; |
| 103 | + return; |
| 104 | + |
| 105 | +error: |
| 106 | + close(fd); |
| 107 | + syslog(LOG_ERR, "RF_Lock: failed to send the message: %d\n", errno); |
| 108 | + return; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | -- |
| 113 | 1.7.10.4 |
| 114 | |