mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-27 02:38:33 +03:00
host: use autotools and split shared code to libosmo-simtrace2
Change-Id: I57e77f927ee9e169cc794c5dc6b128a2d590201b
This commit is contained in:
57
host/lib/gsmtap.c
Normal file
57
host/lib/gsmtap.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <osmocom/simtrace2/gsmtap.h>
|
||||
|
||||
#include <osmocom/core/gsmtap.h>
|
||||
#include <osmocom/core/gsmtap_util.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* global GSMTAP instance */
|
||||
static struct gsmtap_inst *g_gti;
|
||||
|
||||
int osmo_st2_gsmtap_init(const char *gsmtap_host)
|
||||
{
|
||||
if (g_gti)
|
||||
return -EEXIST;
|
||||
|
||||
g_gti = gsmtap_source_init(gsmtap_host, GSMTAP_UDP_PORT, 0);
|
||||
if (!g_gti) {
|
||||
perror("unable to open GSMTAP");
|
||||
return -EIO;
|
||||
}
|
||||
gsmtap_source_add_sink(g_gti);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int osmo_st2_gsmtap_send_apdu(uint8_t sub_type, const uint8_t *apdu, unsigned int len)
|
||||
{
|
||||
struct gsmtap_hdr *gh;
|
||||
unsigned int gross_len = len + sizeof(*gh);
|
||||
uint8_t *buf = malloc(gross_len);
|
||||
int rc;
|
||||
|
||||
if (!buf)
|
||||
return -ENOMEM;
|
||||
|
||||
memset(buf, 0, sizeof(*gh));
|
||||
gh = (struct gsmtap_hdr *) buf;
|
||||
gh->version = GSMTAP_VERSION;
|
||||
gh->hdr_len = sizeof(*gh)/4;
|
||||
gh->type = GSMTAP_TYPE_SIM;
|
||||
gh->sub_type = sub_type;
|
||||
|
||||
memcpy(buf + sizeof(*gh), apdu, len);
|
||||
|
||||
rc = write(gsmtap_inst_fd(g_gti), buf, gross_len);
|
||||
if (rc < 0) {
|
||||
perror("write gsmtap");
|
||||
free(buf);
|
||||
return rc;
|
||||
}
|
||||
|
||||
free(buf);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user