Add missing p25cai class (lost during check-in).
git-svn-id: http://op25.osmocom.org/svn/trunk@252 65a5c917-d112-43f1-993d-58c26a4786be
This commit is contained in:
parent
034d65b7b1
commit
431bc45d8a
|
@ -0,0 +1,85 @@
|
|||
/* -*- C++ -*- */
|
||||
|
||||
/*
|
||||
* Copyright 2008-2011 Steve Glass
|
||||
*
|
||||
* This file is part of OP25.
|
||||
*
|
||||
* OP25 is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* OP25 is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OP25; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <iomanip>
|
||||
#include <netinet/in.h>
|
||||
#include <p25cai_du_handler.h>
|
||||
#include <sstream>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
p25cai_du_handler::p25cai_du_handler(data_unit_handler_sptr next, const char *addr, int port) :
|
||||
data_unit_handler(next),
|
||||
d_cai(-1),
|
||||
d_address("Unavailable")
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_port = htons(port);
|
||||
inet_aton(addr, &sin.sin_addr);
|
||||
d_cai = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if(-1 != d_cai) {
|
||||
if(-1 == connect(d_cai, (struct sockaddr*) &sin, sizeof(sin))) {
|
||||
ostringstream address;
|
||||
address << addr << ":" << port;
|
||||
d_address = address.str();
|
||||
} else {
|
||||
perror("connect(d_tap, (struct sockaddr*) &sin, sizeof(sin))");
|
||||
close(d_cai);
|
||||
d_cai = -1;
|
||||
}
|
||||
} else {
|
||||
perror("socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)");
|
||||
d_cai = -1;
|
||||
}
|
||||
}
|
||||
|
||||
p25cai_du_handler::~p25cai_du_handler()
|
||||
{
|
||||
if(-1 != d_cai) {
|
||||
close(d_cai);
|
||||
}
|
||||
}
|
||||
|
||||
const char*
|
||||
p25cai_du_handler::destination() const
|
||||
{
|
||||
return d_address.c_str();
|
||||
}
|
||||
|
||||
void
|
||||
p25cai_du_handler::handle(data_unit_sptr du)
|
||||
{
|
||||
if(-1 != d_cai) {
|
||||
const size_t CAI_SZ = du->size();
|
||||
uint8_t cai[CAI_SZ];
|
||||
du->decode_frame(CAI_SZ, cai);
|
||||
write(d_cai, cai, CAI_SZ);
|
||||
}
|
||||
data_unit_handler::handle(du);
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/* -*- C++ -*- */
|
||||
|
||||
/*
|
||||
* Copyright 2008-2011 Steve Glass
|
||||
*
|
||||
* This file is part of OP25.
|
||||
*
|
||||
* OP25 is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* OP25 is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OP25; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_P25CAI_DU_HANDLER_H
|
||||
#define INCLUDED_P25CAI_DU_HANDLER_H
|
||||
|
||||
#include <data_unit_handler.h>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* This data_unit_handler forwards received frames using p25cai - a
|
||||
* straighforward encapsulation of the P25 CAI in a UDP datagram. This
|
||||
* format is understood by Wireshark and replaces the use of TUN/TAP
|
||||
* which require root privileges and are not present by default on
|
||||
* some platforms.
|
||||
*/
|
||||
class p25cai_du_handler : public data_unit_handler
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* p25cai_du_handler constructor.
|
||||
*
|
||||
* \param next The next data_unit_handler.
|
||||
* \param addr The address of the receiver.
|
||||
* \param port The port number of the receiver.
|
||||
*/
|
||||
p25cai_du_handler(data_unit_handler_sptr next, const char *addr, int port);
|
||||
|
||||
/**
|
||||
* p25cai_du_handler virtual destructor.
|
||||
*/
|
||||
virtual ~p25cai_du_handler();
|
||||
|
||||
/**
|
||||
* Handle a received P25 frame.
|
||||
*
|
||||
* \param du A non-null data_unit_sptr to handle.
|
||||
*/
|
||||
virtual void handle(data_unit_sptr du);
|
||||
|
||||
/**
|
||||
* Return a pointer to a string identifying the destination address.
|
||||
*
|
||||
* \return A pointer to a NUL-terminated character string.
|
||||
*/
|
||||
const char *destination() const;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* file descriptor for the UDP socket.
|
||||
*/
|
||||
int32_t d_cai;
|
||||
|
||||
/**
|
||||
* A string identifying the address of the receiver.
|
||||
*/
|
||||
std::string d_address;
|
||||
|
||||
};
|
||||
|
||||
#endif /* INCLUDED_P25CAI_DU_HANDLER_H */
|
Reference in New Issue