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.
This commit is contained in:
parent
d0e38c3cad
commit
f87573dc4e
|
@ -32,6 +32,7 @@ struct telnet_connection {
|
||||||
struct llist_head entry;
|
struct llist_head entry;
|
||||||
struct gsm_network *network;
|
struct gsm_network *network;
|
||||||
struct bsc_fd fd;
|
struct bsc_fd fd;
|
||||||
|
int bts;
|
||||||
|
|
||||||
int command;
|
int command;
|
||||||
char *imsi;
|
char *imsi;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
|
|
||||||
#include <openbsc/telnet_interface.h>
|
#include <openbsc/telnet_interface.h>
|
||||||
#include <openbsc/gsm_subscriber.h>
|
#include <openbsc/gsm_subscriber.h>
|
||||||
|
#include <openbsc/chan_alloc.h>
|
||||||
|
|
||||||
extern void telnet_parse(struct telnet_connection *connection, char *line);
|
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);
|
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) {
|
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) {
|
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,
|
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.fd = new_connection;
|
||||||
connection->fd.when = BSC_FD_READ;
|
connection->fd.when = BSC_FD_READ;
|
||||||
connection->fd.cb = client_data;
|
connection->fd.cb = client_data;
|
||||||
|
connection->bts = 0;
|
||||||
bsc_register_fd(&connection->fd);
|
bsc_register_fd(&connection->fd);
|
||||||
llist_add_tail(&connection->entry, &active_connections);
|
llist_add_tail(&connection->entry, &active_connections);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue