osmo-e1d-pipe: Add command line option for --force open of timeslot
This exposes the existing capability of force-opening a timeslot via a command-line argument. Related: OS#5735 Change-Id: Ieefc89f2e48e9124ae744a587739ff3948110944
This commit is contained in:
parent
5077657f57
commit
cfe7ab300e
|
@ -1,6 +1,6 @@
|
||||||
/* E1 timeslot "pipe" utility: Open a 64k timeslot of osmo-e1d and connect to stdin/stdout
|
/* E1 timeslot "pipe" utility: Open a 64k timeslot of osmo-e1d and connect to stdin/stdout
|
||||||
*
|
*
|
||||||
* (C) 2020 by Harald Welte <laforge@osmocom.org>
|
* (C) 2020-2022 by Harald Welte <laforge@osmocom.org>
|
||||||
*
|
*
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
*
|
*
|
||||||
|
@ -22,6 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -40,6 +41,7 @@ static void *g_ctx;
|
||||||
static struct osmo_e1dp_client *g_client;
|
static struct osmo_e1dp_client *g_client;
|
||||||
static struct osmo_fd ts_ofd;
|
static struct osmo_fd ts_ofd;
|
||||||
static enum osmo_e1dp_ts_mode g_mode = E1DP_TSMODE_RAW;
|
static enum osmo_e1dp_ts_mode g_mode = E1DP_TSMODE_RAW;
|
||||||
|
static bool g_force = false;
|
||||||
static int outfd = 1;
|
static int outfd = 1;
|
||||||
static int infd = 0;
|
static int infd = 0;
|
||||||
|
|
||||||
|
@ -47,7 +49,11 @@ static int infd = 0;
|
||||||
static int ts_open(uint8_t intf_nr, uint8_t line_nr, uint8_t ts_nr,
|
static int ts_open(uint8_t intf_nr, uint8_t line_nr, uint8_t ts_nr,
|
||||||
enum osmo_e1dp_ts_mode mode, uint16_t bufsize)
|
enum osmo_e1dp_ts_mode mode, uint16_t bufsize)
|
||||||
{
|
{
|
||||||
int rc = osmo_e1dp_client_ts_open(g_client, intf_nr, line_nr, ts_nr, mode, bufsize);
|
int rc;
|
||||||
|
if (g_force)
|
||||||
|
rc = osmo_e1dp_client_ts_open_force(g_client, intf_nr, line_nr, ts_nr, mode, bufsize);
|
||||||
|
else
|
||||||
|
rc = osmo_e1dp_client_ts_open(g_client, intf_nr, line_nr, ts_nr, mode, bufsize);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
fprintf(stderr, "Cannot open e1d timeslot %u:%u:%u\n", intf_nr, line_nr, ts_nr);
|
fprintf(stderr, "Cannot open e1d timeslot %u:%u:%u\n", intf_nr, line_nr, ts_nr);
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -118,6 +124,7 @@ static void print_help(void)
|
||||||
" -l --line <0-255> E1 Line Number\n"
|
" -l --line <0-255> E1 Line Number\n"
|
||||||
" -t --timeslot <0-31> E1 Timeslot Number\n"
|
" -t --timeslot <0-31> E1 Timeslot Number\n"
|
||||||
" -m --mode (RAW|HDLC-FCS) E1 Timeslot Mode\n"
|
" -m --mode (RAW|HDLC-FCS) E1 Timeslot Mode\n"
|
||||||
|
" -f --force Force open of the timeslot (may disconnect other client)\n"
|
||||||
" -r --read FILE Read from FILE instead of STDIN\n"
|
" -r --read FILE Read from FILE instead of STDIN\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -145,12 +152,13 @@ int main(int argc, char **argv)
|
||||||
{ "line", 1, 0, 'l' },
|
{ "line", 1, 0, 'l' },
|
||||||
{ "timeslot", 1, 0, 't' },
|
{ "timeslot", 1, 0, 't' },
|
||||||
{ "mode", 1, 0, 'm' },
|
{ "mode", 1, 0, 'm' },
|
||||||
|
{ "force", 0, 0, 'f' },
|
||||||
{ "read", 1, 0, 'r' },
|
{ "read", 1, 0, 'r' },
|
||||||
{ "read-bufsize", 1, 0, 'b' },
|
{ "read-bufsize", 1, 0, 'b' },
|
||||||
{ 0,0,0,0 }
|
{ 0,0,0,0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
c = getopt_long(argc, argv, "hp:i:l:t:m:r:b:", long_options, &option_index);
|
c = getopt_long(argc, argv, "hp:i:l:t:m:fr:b:", long_options, &option_index);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -178,6 +186,9 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
g_mode = rc;
|
g_mode = rc;
|
||||||
break;
|
break;
|
||||||
|
case 'f':
|
||||||
|
g_force = true;
|
||||||
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
rc = open(optarg, 0, O_RDONLY);
|
rc = open(optarg, 0, O_RDONLY);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
|
Loading…
Reference in New Issue