aboutsummaryrefslogtreecommitdiffstats
path: root/src/telnet_interface.c
diff options
context:
space:
mode:
authorHolger Freyther <zecke@selfish.org>2009-01-04 03:49:41 +0000
committerHolger Freyther <zecke@selfish.org>2009-01-04 03:49:41 +0000
commitf87573dc4e8e22e81ab6f9e4e9a241bba747fe52 (patch)
tree195c3a8eb0ad3c628dd0eb7775c20b39c38b1054 /src/telnet_interface.c
parentd0e38c3cadc8f13e85aef184a1155d34bf99a1f5 (diff)
Implement put_channel/get_channel, save on which bts we currently operate
Allow to change the refcount for a given channel. Store which bts is our primary bts. A command to switch the primary bts will be added as well. This makes entering and parsing of commands more easy.
Diffstat (limited to 'src/telnet_interface.c')
-rw-r--r--src/telnet_interface.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/src/telnet_interface.c b/src/telnet_interface.c
index 68755481d..dc93df192 100644
--- a/src/telnet_interface.c
+++ b/src/telnet_interface.c
@@ -27,6 +27,7 @@
#include <openbsc/telnet_interface.h>
#include <openbsc/gsm_subscriber.h>
+#include <openbsc/chan_alloc.h>
extern void telnet_parse(struct telnet_connection *connection, char *line);
@@ -136,12 +137,50 @@ void telnet_page(struct telnet_connection *connection, const char *imsi, int pag
printf("going to page: '%s' %d\n", imsi, page);
}
+static struct gsm_lchan* find_channel(struct gsm_bts *bts, const char *imsi,
+ const char **error, int fd) {
+ int ret;
+ struct gsm_lchan *lchan;
+ struct gsm_subscriber *subscr;
+
+ subscr = subscr_get_by_imsi(imsi);
+ if (!subscr) {
+ ret = write(fd, error[0], strlen(error[0]));
+ return NULL;
+ }
+
+ lchan = lchan_find(bts, subscr);
+ if (!lchan)
+ ret = write(fd, error[1], strlen(error[1]));
+
+ subscr_put(subscr);
+ return lchan;
+}
+
void telnet_put_channel(struct telnet_connection *connection, const char *imsi) {
- printf("put_channel: '%s'\n", imsi);
+ static const char* error[] = {
+ "put_channel: IMSI not found\n",
+ "put_channel: No channel allocated for IMSI\n" };
+ struct gsm_bts *bts = &connection->network->bts[connection->bts];
+ struct gsm_lchan *lchan = find_channel(bts, imsi, error, connection->fd.fd);
+
+ if (!lchan)
+ return;
+
+ put_lchan(lchan);
}
void telnet_get_channel(struct telnet_connection *connection, const char *imsi) {
- printf("get_channel: '%s'\n", imsi);
+ static const char* error[] = {
+ "get_channel: IMSI not found\n",
+ "get_channel: No channel allocated for IMSI\n" };
+ struct gsm_bts *bts = &connection->network->bts[connection->bts];
+ struct gsm_lchan *lchan = find_channel(bts, imsi, error, connection->fd.fd);
+
+ if (!lchan)
+ return;
+
+ use_lchan(lchan);
}
void telnet_call(struct telnet_connection *connection, const char* imsi,
@@ -245,6 +284,7 @@ static int telnet_new_connection(struct bsc_fd *fd, unsigned int what) {
connection->fd.fd = new_connection;
connection->fd.when = BSC_FD_READ;
connection->fd.cb = client_data;
+ connection->bts = 0;
bsc_register_fd(&connection->fd);
llist_add_tail(&connection->entry, &active_connections);