astyle --recursive --indent=spaces=2 --style=kr --indent-col1-comments --break-blocks --convert-tabs --max-code-length=200

This is done for better merging branch/LG_PRE_RELEASE_0.3 into trunk (same process is applied on this branch)

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@7073 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
Lionel Gauthier
2015-04-09 09:29:12 +00:00
parent f0a8a0b3b5
commit 059a0a3fdc
2044 changed files with 1182666 additions and 1145123 deletions
+338 -313
View File
@@ -159,9 +159,9 @@ static int g_socksd = -1;/* UDP socket used for sending frames */
static struct sockaddr_in g_serv_addr;
typedef struct {
pthread_t thread;
int sd;
struct sockaddr_in address;
pthread_t thread;
int sd;
struct sockaddr_in address;
} opt_listener_t;
opt_listener_t opt_listener;
@@ -177,82 +177,83 @@ static int MAC_LTE_PCAP_WritePDU(MAC_Context_Info_t *context,
static void *opt_listener_thread(void *arg)
{
ssize_t ret;
struct sockaddr_in from_address;
socklen_t socklen = sizeof(from_address);
ssize_t ret;
struct sockaddr_in from_address;
socklen_t socklen = sizeof(from_address);
memset(&from_address, 0, sizeof(from_address));
memset(&from_address, 0, sizeof(from_address));
while(1)
{
/* Simply drop packets */
ret = recvfrom(opt_listener.sd, NULL, 0, 0, (struct sockaddr*)&from_address,
&socklen);
while(1) {
/* Simply drop packets */
ret = recvfrom(opt_listener.sd, NULL, 0, 0, (struct sockaddr*)&from_address,
&socklen);
if (ret == 0) {
LOG_D(OPT, "Remote host is no more connected, exiting thread\n");
pthread_exit(NULL);
} else if (ret < 0) {
/* Errors */
LOG_E(OPT, "An error occured during recvfrom: %s\n", strerror(errno));
pthread_exit(NULL);
} else {
/* Normal read -> discard PDU */
LOG_D(OPT, "Incoming data received from: %s:%u with length %d\n",
inet_ntoa(opt_listener.address.sin_addr),
ntohs(opt_listener.address.sin_port), ret);
}
if (ret == 0) {
LOG_D(OPT, "Remote host is no more connected, exiting thread\n");
pthread_exit(NULL);
} else if (ret < 0) {
/* Errors */
LOG_E(OPT, "An error occured during recvfrom: %s\n", strerror(errno));
pthread_exit(NULL);
} else {
/* Normal read -> discard PDU */
LOG_D(OPT, "Incoming data received from: %s:%u with length %d\n",
inet_ntoa(opt_listener.address.sin_addr),
ntohs(opt_listener.address.sin_port), ret);
}
}
return NULL;
return NULL;
}
static
int opt_create_listener_socket(char *ip_address, uint16_t port)
{
/* Create an UDP socket and listen on it.
* Silently discard PDU received.
*/
/* Create an UDP socket and listen on it.
* Silently discard PDU received.
*/
int sd = -1;
int ret = -1;
int sd = -1;
int ret = -1;
memset(&opt_listener, 0, sizeof(opt_listener_t));
memset(&opt_listener, 0, sizeof(opt_listener_t));
sd = socket(AF_INET, SOCK_DGRAM, 0);
if (sd < 0) {
LOG_E(OPT, "Failed to create listener socket: %s\n", strerror(errno));
sd = -1;
opt_type = OPT_NONE;
return -1;
}
sd = socket(AF_INET, SOCK_DGRAM, 0);
opt_listener.sd = sd;
opt_listener.address.sin_family = AF_INET;
/* Listening only on provided IP address */
opt_listener.address.sin_addr.s_addr = inet_addr(ip_address);
opt_listener.address.sin_port = htons(port);
if (sd < 0) {
LOG_E(OPT, "Failed to create listener socket: %s\n", strerror(errno));
sd = -1;
opt_type = OPT_NONE;
return -1;
}
ret = bind(opt_listener.sd, (struct sockaddr*) &opt_listener.address, sizeof(opt_listener.address));
opt_listener.sd = sd;
opt_listener.address.sin_family = AF_INET;
/* Listening only on provided IP address */
opt_listener.address.sin_addr.s_addr = inet_addr(ip_address);
opt_listener.address.sin_port = htons(port);
if (ret != 0) {
LOG_E(OPT, "Failed to bind socket to (%s:%u): %s\n", strerror(errno));
opt_type = OPT_NONE;
close(opt_listener.sd);
opt_listener.sd = -1;
return -1;
}
ret = bind(opt_listener.sd, (struct sockaddr*) &opt_listener.address, sizeof(opt_listener.address));
ret = pthread_create(&opt_listener.thread, NULL, opt_listener_thread, NULL);
if (ret != 0) {
LOG_E(OPT, "Failed to bind socket to (%s:%u): %s\n", strerror(errno));
opt_type = OPT_NONE;
close(opt_listener.sd);
opt_listener.sd = -1;
return -1;
}
if (ret != 0) {
LOG_E(OPT, "Failed to create thread for server socket: %s\n", strerror(errno));
opt_type = OPT_NONE;
close(opt_listener.sd);
opt_listener.sd = -1;
return -1;
}
return 0;
ret = pthread_create(&opt_listener.thread, NULL, opt_listener_thread, NULL);
if (ret != 0) {
LOG_E(OPT, "Failed to create thread for server socket: %s\n", strerror(errno));
opt_type = OPT_NONE;
close(opt_listener.sd);
opt_listener.sd = -1;
return -1;
}
return 0;
}
//struct mac_lte_info * mac_info;
@@ -272,185 +273,191 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
guint8 oob_event, guint8 oob_event_value,
uint8_t *pdu_buffer, unsigned int pdu_buffer_size)
{
ssize_t bytesSent;
g_frameOffset = 0;
uint16_t tmp16;
ssize_t bytesSent;
g_frameOffset = 0;
uint16_t tmp16;
/********************************************************************/
/* Fixed start to each frame (allowing heuristic dissector to work) */
/* Not NULL terminated */
memset(g_frameBuffer+g_frameOffset, 0, sizeof(mac_lte_info)+pdu_buffer_size + 8);
/********************************************************************/
/* Fixed start to each frame (allowing heuristic dissector to work) */
/* Not NULL terminated */
memset(g_frameBuffer+g_frameOffset, 0, sizeof(mac_lte_info)+pdu_buffer_size + 8);
memcpy(g_frameBuffer+g_frameOffset, MAC_LTE_START_STRING,
strlen(MAC_LTE_START_STRING));
g_frameOffset += strlen(MAC_LTE_START_STRING);
memcpy(g_frameBuffer+g_frameOffset, MAC_LTE_START_STRING,
strlen(MAC_LTE_START_STRING));
g_frameOffset += strlen(MAC_LTE_START_STRING);
/******************************************************************************/
/* Now write out fixed fields (the mandatory elements of struct mac_lte_info) */
g_frameBuffer[g_frameOffset++] = radioType;
g_frameBuffer[g_frameOffset++] = direction;
g_frameBuffer[g_frameOffset++] = rntiType;
/******************************************************************************/
/* Now write out fixed fields (the mandatory elements of struct mac_lte_info) */
g_frameBuffer[g_frameOffset++] = radioType;
g_frameBuffer[g_frameOffset++] = direction;
g_frameBuffer[g_frameOffset++] = rntiType;
/*************************************/
/* Now optional fields */
/*************************************/
/* Now optional fields */
/* RNTI */
g_frameBuffer[g_frameOffset++] = MAC_LTE_RNTI_TAG;
tmp16 = htons(rnti);
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
/* RNTI */
g_frameBuffer[g_frameOffset++] = MAC_LTE_RNTI_TAG;
tmp16 = htons(rnti);
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
/* UEId */
g_frameBuffer[g_frameOffset++] = MAC_LTE_UEID_TAG;
tmp16 = htons(ueid);
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
/* UEId */
g_frameBuffer[g_frameOffset++] = MAC_LTE_UEID_TAG;
tmp16 = htons(ueid);
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
/* Subframe number */
g_frameBuffer[g_frameOffset++] = MAC_LTE_SUBFRAME_TAG;
tmp16 = htons(subframeNumber); // frame counter : this will give an expert info as wireshark expects SF and not F
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
/* Subframe number */
g_frameBuffer[g_frameOffset++] = MAC_LTE_SUBFRAME_TAG;
tmp16 = htons(subframeNumber); // frame counter : this will give an expert info as wireshark expects SF and not F
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
#ifdef WIRESHARK_DEV
g_frameOffset += 2;
tmp16 = htons(subframeNumber); // subframe
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
g_frameOffset += 2;
tmp16 = htons(subframeNumber); // subframe
memcpy(g_frameBuffer+g_frameOffset, &tmp16, 2);
g_frameOffset += 2;
#endif
/***********************************************************/
/* For these optional fields, no need to encode if value is default */
if (!isPredefinedData) {
g_frameBuffer[g_frameOffset++] = MAC_LTE_PREDEFINED_DATA_TAG;
g_frameBuffer[g_frameOffset++] = isPredefinedData;
}
if (retx != 0) {
g_frameBuffer[g_frameOffset++] = MAC_LTE_RETX_TAG;
g_frameBuffer[g_frameOffset++] = retx;
}
/***********************************************************/
/* For these optional fields, no need to encode if value is default */
if (!isPredefinedData) {
g_frameBuffer[g_frameOffset++] = MAC_LTE_PREDEFINED_DATA_TAG;
g_frameBuffer[g_frameOffset++] = isPredefinedData;
}
g_frameBuffer[g_frameOffset++] = MAC_LTE_CRC_STATUS_TAG;
g_frameBuffer[g_frameOffset++] = crcStatus;
if (retx != 0) {
g_frameBuffer[g_frameOffset++] = MAC_LTE_RETX_TAG;
g_frameBuffer[g_frameOffset++] = retx;
}
g_frameBuffer[g_frameOffset++] = MAC_LTE_CRC_STATUS_TAG;
g_frameBuffer[g_frameOffset++] = crcStatus;
#ifdef WIRESHARK_DEV
/* Relating to out-of-band events */
/* N.B. dissector will only look to these fields if length is 0... */
if (pdu_buffer_size==0) {
switch (oob_event) {
case ltemac_send_preamble :
LOG_D(OPT,"oob event %d %d\n",ltemac_send_preamble );
//g_frameBuffer[g_frameOffset++]=0;
//g_frameBuffer[g_frameOffset++]=0;
//g_frameBuffer[g_frameOffset++]=0;
g_frameBuffer[g_frameOffset++] = MAC_LTE_OOB_EVENT_TAG;
g_frameBuffer[g_frameOffset++]=ltemac_send_preamble;
g_frameBuffer[g_frameOffset++]=rnti; // is the preamble
g_frameBuffer[g_frameOffset++]=oob_event_value;
break;
case ltemac_send_sr:
g_frameBuffer[g_frameOffset++]=ltemac_send_sr;
g_frameOffset+=2;
g_frameBuffer[g_frameOffset++]=oob_event_value;
break;
case ltemac_sr_failure:
default:
LOG_D(OPT,"not implemeneted yet\n");
break;
}
/* Relating to out-of-band events */
/* N.B. dissector will only look to these fields if length is 0... */
if (pdu_buffer_size==0) {
switch (oob_event) {
case ltemac_send_preamble :
LOG_D(OPT,"oob event %d %d\n",ltemac_send_preamble );
//g_frameBuffer[g_frameOffset++]=0;
//g_frameBuffer[g_frameOffset++]=0;
//g_frameBuffer[g_frameOffset++]=0;
g_frameBuffer[g_frameOffset++] = MAC_LTE_OOB_EVENT_TAG;
g_frameBuffer[g_frameOffset++]=ltemac_send_preamble;
g_frameBuffer[g_frameOffset++]=rnti; // is the preamble
g_frameBuffer[g_frameOffset++]=oob_event_value;
break;
case ltemac_send_sr:
g_frameBuffer[g_frameOffset++]=ltemac_send_sr;
g_frameOffset+=2;
g_frameBuffer[g_frameOffset++]=oob_event_value;
break;
case ltemac_sr_failure:
default:
LOG_D(OPT,"not implemeneted yet\n");
break;
}
}
#endif
g_frameBuffer[g_frameOffset++] = MAC_LTE_PAYLOAD_TAG;
/***************************************/
/* Now write the MAC PDU */
g_frameBuffer[g_frameOffset++] = MAC_LTE_PAYLOAD_TAG;
/***************************************/
/* Now write the MAC PDU */
/* Append actual PDU */
//memcpy(g_frameBuffer+g_frameOffset, g_PDUBuffer, g_PDUOffset);
//g_frameOffset += g_PDUOffset;
if (pdu_buffer != NULL) {
memcpy(g_frameBuffer+g_frameOffset, (void*)pdu_buffer, pdu_buffer_size);
g_frameOffset += pdu_buffer_size;
}
/* Append actual PDU */
//memcpy(g_frameBuffer+g_frameOffset, g_PDUBuffer, g_PDUOffset);
//g_frameOffset += g_PDUOffset;
if (pdu_buffer != NULL) {
memcpy(g_frameBuffer+g_frameOffset, (void*)pdu_buffer, pdu_buffer_size);
g_frameOffset += pdu_buffer_size;
}
/* Send out the data over the UDP socket */
bytesSent = sendto(g_socksd, g_frameBuffer, g_frameOffset, 0,
(const struct sockaddr *)&g_serv_addr, sizeof(g_serv_addr));
if (bytesSent != g_frameOffset) {
LOG_E(OPT, "sendto() failed - expected %d bytes, got %d (errno=%d)\n",
g_frameOffset, bytesSent, errno);
exit(1);
}
/* Send out the data over the UDP socket */
bytesSent = sendto(g_socksd, g_frameBuffer, g_frameOffset, 0,
(const struct sockaddr *)&g_serv_addr, sizeof(g_serv_addr));
if (bytesSent != g_frameOffset) {
LOG_E(OPT, "sendto() failed - expected %d bytes, got %d (errno=%d)\n",
g_frameOffset, bytesSent, errno);
exit(1);
}
}
/* Write an individual PDU (PCAP packet header + mac-context + mac-pdu) */
static int MAC_LTE_PCAP_WritePDU(MAC_Context_Info_t *context,
const uint8_t *PDU, unsigned int length)
{
pcaprec_hdr_t packet_header;
uint8_t context_header[256];
int offset = 0;
unsigned short tmp16;
pcaprec_hdr_t packet_header;
uint8_t context_header[256];
int offset = 0;
unsigned short tmp16;
/*****************************************************************/
/* Context information (same as written by UDP heuristic clients */
context_header[offset++] = context->radioType;
context_header[offset++] = context->direction;
context_header[offset++] = context->rntiType;
/*****************************************************************/
/* Context information (same as written by UDP heuristic clients */
context_header[offset++] = context->radioType;
context_header[offset++] = context->direction;
context_header[offset++] = context->rntiType;
/* RNTI */
context_header[offset++] = MAC_LTE_RNTI_TAG;
tmp16 = htons(context->rnti);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* RNTI */
context_header[offset++] = MAC_LTE_RNTI_TAG;
tmp16 = htons(context->rnti);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* UEId */
context_header[offset++] = MAC_LTE_UEID_TAG;
tmp16 = htons(context->ueid);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* UEId */
context_header[offset++] = MAC_LTE_UEID_TAG;
tmp16 = htons(context->ueid);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* Subframe number */
context_header[offset++] = MAC_LTE_SUBFRAME_TAG;
tmp16 = htons(context->subFrameNumber);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* Subframe number */
context_header[offset++] = MAC_LTE_SUBFRAME_TAG;
tmp16 = htons(context->subFrameNumber);
memcpy(context_header+offset, &tmp16, 2);
offset += 2;
/* CRC Status */
context_header[offset++] = MAC_LTE_CRC_STATUS_TAG;
context_header[offset++] = context->crcStatusOK;
/* CRC Status */
context_header[offset++] = MAC_LTE_CRC_STATUS_TAG;
context_header[offset++] = context->crcStatusOK;
/* Data tag immediately preceding PDU */
context_header[offset++] = MAC_LTE_PAYLOAD_TAG;
/* Data tag immediately preceding PDU */
context_header[offset++] = MAC_LTE_PAYLOAD_TAG;
/****************************************************************/
/* PCAP Header */
/* TODO: Timestamp might want to be relative to a more sensible
base time... */
/****************************************************************/
/* PCAP Header */
/* TODO: Timestamp might want to be relative to a more sensible
base time... */
#if defined(RTAI)
{
unsigned long long int current_ns;
{
unsigned long long int current_ns;
current_ns = rt_get_time_ns();
packet_header.ts_sec = current_ns / 1000000000UL;
packet_header.ts_usec = current_ns % 1000;
}
current_ns = rt_get_time_ns();
packet_header.ts_sec = current_ns / 1000000000UL;
packet_header.ts_usec = current_ns % 1000;
}
#else
packet_header.ts_sec = context->subframesSinceCaptureStart / 1000;
packet_header.ts_usec = (context->subframesSinceCaptureStart % 1000) * 1000;
packet_header.ts_sec = context->subframesSinceCaptureStart / 1000;
packet_header.ts_usec = (context->subframesSinceCaptureStart % 1000) * 1000;
#endif
packet_header.incl_len = offset + length;
packet_header.orig_len = offset + length;
packet_header.incl_len = offset + length;
packet_header.orig_len = offset + length;
/***************************************************************/
/* Now write everything to the file */
fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, file_fd);
fwrite(context_header, 1, offset, file_fd);
fwrite(PDU, 1, length, file_fd);
/***************************************************************/
/* Now write everything to the file */
fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, file_fd);
fwrite(context_header, 1, offset, file_fd);
fwrite(PDU, 1, length, file_fd);
return 1;
return 1;
}
/* Remote serveraddress (where Wireshark is running) */
@@ -458,133 +465,151 @@ void trace_pdu(int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
int ueid, int rntiType, int rnti, uint8_t subframe, int oob_event,
int oob_event_value)
{
MAC_Context_Info_t pdu_context;
MAC_Context_Info_t pdu_context;
switch (opt_type) {
case OPT_WIRESHARK :
if (g_socksd == -1) {
return;
}
SendFrame(radio_type,
(direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
rntiType, rnti, ueid, subframe,
1, 0, 1, //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
oob_event,oob_event_value,
pdu_buffer, pdu_buffer_size);
break;
case OPT_PCAP:
if (file_fd == NULL) {
return;
}
pdu_context.radioType = radio_type;
pdu_context.direction = (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK
: DIRECTION_UPLINK;
pdu_context.rntiType = rntiType;
pdu_context.rnti = rnti;
pdu_context.ueid = ueid;
pdu_context.isRetx = 0;
pdu_context.crcStatusOK =1;
pdu_context.sysFrameNumber = subframe;
pdu_context.subFrameNumber = 0;
pdu_context.subframesSinceCaptureStart = subframesSinceCaptureStart++;
MAC_LTE_PCAP_WritePDU( &pdu_context, pdu_buffer, pdu_buffer_size);
break;
case OPT_TSHARK:
default:
break;
switch (opt_type) {
case OPT_WIRESHARK :
if (g_socksd == -1) {
return;
}
SendFrame(radio_type,
(direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
rntiType, rnti, ueid, subframe,
1, 0, 1, //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
oob_event,oob_event_value,
pdu_buffer, pdu_buffer_size);
break;
case OPT_PCAP:
if (file_fd == NULL) {
return;
}
pdu_context.radioType = radio_type;
pdu_context.direction = (direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK
: DIRECTION_UPLINK;
pdu_context.rntiType = rntiType;
pdu_context.rnti = rnti;
pdu_context.ueid = ueid;
pdu_context.isRetx = 0;
pdu_context.crcStatusOK =1;
pdu_context.sysFrameNumber = subframe;
pdu_context.subFrameNumber = 0;
pdu_context.subframesSinceCaptureStart = subframesSinceCaptureStart++;
MAC_LTE_PCAP_WritePDU( &pdu_context, pdu_buffer, pdu_buffer_size);
break;
case OPT_TSHARK:
default:
break;
}
}
/*---------------------------------------------------*/
int init_opt(char *path, char *ip, char *port, radio_type_t radio_type_p)
{
subframesSinceCaptureStart = 0;
subframesSinceCaptureStart = 0;
if (path != NULL) {
strncpy( in_path, path, sizeof(in_path) );
in_path[sizeof(in_path) - 1] = 0; // terminate string
} else {
strcpy( in_path, "/tmp/oai_opt.pcap" );
}
if (ip != NULL) {
strncpy( in_ip, ip, sizeof(in_ip) );
in_ip[sizeof(in_ip) - 1] = 0; // terminate string
} else {
strcpy( in_ip, "127.0.0.1" );
}
if (port != NULL) {
in_port = atoi(port);
} else {
in_port = PACKET_MAC_LTE_DEFAULT_UDP_PORT;
if (path != NULL) {
strncpy( in_path, path, sizeof(in_path) );
in_path[sizeof(in_path) - 1] = 0; // terminate string
} else {
strcpy( in_path, "/tmp/oai_opt.pcap" );
}
if (ip != NULL) {
strncpy( in_ip, ip, sizeof(in_ip) );
in_ip[sizeof(in_ip) - 1] = 0; // terminate string
} else {
strcpy( in_ip, "127.0.0.1" );
}
if (port != NULL) {
in_port = atoi(port);
} else {
in_port = PACKET_MAC_LTE_DEFAULT_UDP_PORT;
}
radio_type = radio_type_p;
// trace_mode
switch (opt_type) {
case OPT_WIRESHARK:
/* Create local server socket only if using localhost address */
if (strcmp(in_ip, "127.0.0.1") == 0) {
opt_create_listener_socket(in_ip, in_port);
}
radio_type = radio_type_p;
g_socksd = socket(AF_INET, SOCK_DGRAM, 0);
// trace_mode
switch (opt_type) {
case OPT_WIRESHARK:
/* Create local server socket only if using localhost address */
if (strcmp(in_ip, "127.0.0.1") == 0) {
opt_create_listener_socket(in_ip, in_port);
}
g_socksd = socket(AF_INET, SOCK_DGRAM, 0);
if (g_socksd == -1) {
LOG_E(OPT, "Error trying to create socket (errno=%d)\n", errno);
LOG_E(OPT, "CREATING SOCKET FAILED\n");
return (-1);
}
/* Get remote IP address from the function argument */
g_serv_addr.sin_family = AF_INET;
g_serv_addr.sin_port = htons(in_port);
g_serv_addr.sin_addr.s_addr = inet_addr(in_ip);
break;
case OPT_PCAP:
file_fd = fopen(in_path, "w");
if (file_fd == NULL) {
LOG_D(OPT, "Failed to open file \"%s\" for writing\n", in_path);
return (-1);
}
/* Write the file header */
fwrite(&file_header, sizeof(pcap_hdr_t), 1, file_fd);
break;
case OPT_TSHARK:
LOG_D(OPT, "Tshark is currently not supported\n");
opt_type = OPT_NONE;
break;
default:
opt_type = OPT_NONE;
break;
if (g_socksd == -1) {
LOG_E(OPT, "Error trying to create socket (errno=%d)\n", errno);
LOG_E(OPT, "CREATING SOCKET FAILED\n");
return (-1);
}
if ( opt_type == OPT_WIRESHARK )
LOG_G(OPT,"mode Wireshark: ip %s port %d\n", in_ip, in_port);
else if (opt_type == OPT_PCAP)
LOG_G(OPT,"mode PCAB : path is %s \n",in_path);
else
LOG_G(OPT,"Unsupported or unknown mode %d \n", opt_type);
// mac_info = (mac_info*)malloc16(sizeof(mac_lte_info));
// memset(mac_info, 0, sizeof(mac_lte_info)+pdu_buffer_size + 8);
return (1);
/* Get remote IP address from the function argument */
g_serv_addr.sin_family = AF_INET;
g_serv_addr.sin_port = htons(in_port);
g_serv_addr.sin_addr.s_addr = inet_addr(in_ip);
break;
case OPT_PCAP:
file_fd = fopen(in_path, "w");
if (file_fd == NULL) {
LOG_D(OPT, "Failed to open file \"%s\" for writing\n", in_path);
return (-1);
}
/* Write the file header */
fwrite(&file_header, sizeof(pcap_hdr_t), 1, file_fd);
break;
case OPT_TSHARK:
LOG_D(OPT, "Tshark is currently not supported\n");
opt_type = OPT_NONE;
break;
default:
opt_type = OPT_NONE;
break;
}
if ( opt_type == OPT_WIRESHARK )
LOG_G(OPT,"mode Wireshark: ip %s port %d\n", in_ip, in_port);
else if (opt_type == OPT_PCAP)
LOG_G(OPT,"mode PCAB : path is %s \n",in_path);
else
LOG_G(OPT,"Unsupported or unknown mode %d \n", opt_type);
// mac_info = (mac_info*)malloc16(sizeof(mac_lte_info));
// memset(mac_info, 0, sizeof(mac_lte_info)+pdu_buffer_size + 8);
return (1);
}
void terminate_opt(void)
{
/* Close local socket */
// free(mac_info);
if (opt_type != OPT_NONE) {
pthread_cancel(opt_listener.thread);
}
switch (opt_type) {
case OPT_WIRESHARK:
close(g_socksd);
g_socksd = -1;
break;
case OPT_PCAP:
fclose (file_fd);
file_fd = NULL;
break;
default:
break;
}
/* Close local socket */
// free(mac_info);
if (opt_type != OPT_NONE) {
pthread_cancel(opt_listener.thread);
}
switch (opt_type) {
case OPT_WIRESHARK:
close(g_socksd);
g_socksd = -1;
break;
case OPT_PCAP:
fclose (file_fd);
file_fd = NULL;
break;
default:
break;
}
}
/*
double *timing_analyzer(int index, int direction ){