Removed ph_socket, it is now a lib

master
Andreas Eversberg 4 months ago
parent bc888d85cc
commit be40b44515
  1. 1
      .gitignore
  2. 1
      configure.ac
  3. 1
      src/Makefile.am
  4. 2
      src/isdn/Makefile.am
  5. 2
      src/isdn/isdn.h
  6. 8
      src/isdn/ph_driver.c
  7. 7
      src/libph_socket/Makefile.am
  8. 20
      src/libph_socket/ph_socket.c
  9. 4
      src/libph_socket/ph_socket.h

1
.gitignore vendored

@ -40,6 +40,7 @@ src/liboptions/liboptions.a
src/libosmocc/libosmocc.a
src/libsample/libsample.a
src/libtimer/libtimer.a
src/libph_socket/libph_socket.a
src/libmisdn/libmisdn.a
src/libmisdnuser/libmisdnuser.a
src/isdn/osmo-cc-misdn-endpoint

@ -87,6 +87,7 @@ AC_OUTPUT(
src/libjitter/Makefile
src/libosmocc/Makefile
src/libg711/Makefile
src/libph_socket/Makefile
src/libmisdn/Makefile
src/libmisdnuser/Makefile
src/isdn/Makefile

@ -8,6 +8,7 @@ SUBDIRS = \
libjitter \
libosmocc \
libg711 \
libph_socket \
libmisdn \
libmisdnuser \
isdn

@ -8,7 +8,6 @@ osmo_cc_misdn_endpoint_SOURCES = \
dss1.c \
isdn.c \
bridge.c \
ph_socket.c \
ph_driver.c \
main.c
@ -21,6 +20,7 @@ osmo_cc_misdn_endpoint_LDADD = \
../libjitter/libjitter.a \
../libosmocc/libosmocc.a \
../libg711/libg711.a \
../libph_socket/libph_socket.a \
../libmisdn/libmisdn.a \
../libmisdnuser/libmisdnuser.a

@ -5,7 +5,7 @@
#include "../libosmocc/helper.h"
#include "../libsample/sample.h"
#include "../libjitter/jitter.h"
#include "ph_socket.h"
#include "../libph_socket/ph_socket.h"
#define B_MODE_TRANSPARENT 0
#define B_MODE_HDLC 1

@ -20,7 +20,7 @@
#include <stdio.h>
#include <stdint.h>
#include "ph_socket.h"
#include "../libph_socket/ph_socket.h"
#include "ph_driver.h"
#define __MISDNL1L2__
#include "../libmisdn/mISDNhw.h"
@ -166,6 +166,8 @@ static int d_ctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
return err;
}
static void ph_socket_rx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length);
/* init instance of PH-socket driver */
int init_ph_socket_driver(struct ph_socket_driver *drv, void *priv, const char *socket_name, int pri, int nt, uint32_t debug)
{
@ -179,7 +181,7 @@ int init_ph_socket_driver(struct ph_socket_driver *drv, void *priv, const char *
drv->nt = nt;
/* socket client */
ph_socket_init(&drv->ph_socket, drv, socket_name, 0);
ph_socket_init(&drv->ph_socket, ph_socket_rx_msg, drv, socket_name, 0);
/* allocate dchannel structure */
dch = kzalloc(sizeof(*dch), GFP_KERNEL);
@ -246,7 +248,7 @@ void exit_ph_socket_driver(struct ph_socket_driver *drv)
}
/* message from PH-socket to mISDN */
void ph_socket_rx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length)
static void ph_socket_rx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length)
{
struct ph_socket_driver *drv = (struct ph_socket_driver *)s->priv;

@ -0,0 +1,7 @@
AM_CPPFLAGS = -Wall -Wextra -g $(all_includes)
noinst_LIBRARIES = libph_socket.a
libph_socket_a_SOURCES = \
ph_socket.c

@ -32,22 +32,21 @@
#define CHAN s->name
int ph_socket_init(ph_socket_t *s, void *priv, const char *socket_name, int server)
int ph_socket_init(ph_socket_t *s, void (*ph_socket_rx_msg)(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length), void *priv, const char *socket_name, int server)
{
int rc, flags;
memset(s, 0, sizeof(*s));
s->name = socket_name;
s->ph_socket_rx_msg = ph_socket_rx_msg;
s->priv = priv;
s->tx_list_tail = &s->tx_list;
memset(&s->sock_address, 0, sizeof(s->sock_address));
s->sock_address.sun_family = AF_UNIX;
strncpy(s->sock_address.sun_path, socket_name, sizeof(s->sock_address.sun_path) - 1);
strcpy(s->sock_address.sun_path+1, socket_name);
if (server) {
unlink(s->name);
rc = socket(PF_UNIX, SOCK_STREAM, 0);
if (rc < 0) {
PDEBUG_CHAN(DPH, DEBUG_ERROR, "Failed to create UNIX socket.\n");
@ -55,7 +54,7 @@ int ph_socket_init(ph_socket_t *s, void *priv, const char *socket_name, int serv
}
s->listen = rc;
rc = bind(s->listen, (struct sockaddr *)(&s->sock_address), SUN_LEN(&s->sock_address));
rc = bind(s->listen, (struct sockaddr *)(&s->sock_address), sizeof(s->sock_address));
if (rc < 0) {
PDEBUG_CHAN(DPH, DEBUG_ERROR, "Failed to bind UNIX socket with path '%s' (errno = %d (%s)).\n", s->name, errno, strerror(errno));
return rc;
@ -89,7 +88,7 @@ static void close_connection(ph_socket_t *s)
PDEBUG_CHAN(DPH, DEBUG_INFO, "Connection from PH-socket closed.\n");
/* indicate loss of socket connection */
ph_socket_rx_msg(s, 0, (s->listen > 0) ? PH_PRIM_CTRL_REQ : PH_PRIM_CTRL_IND, &disable, 1);
s->ph_socket_rx_msg(s, 0, (s->listen > 0) ? PH_PRIM_CTRL_REQ : PH_PRIM_CTRL_IND, &disable, 1);
close(s->connect);
s->connect = 0;
@ -117,7 +116,6 @@ void ph_socket_exit(ph_socket_t *s)
close_connection(s);
if (s->listen > 0) {
unlink(s->name);
close(s->listen);
s->listen = 0;
}
@ -149,7 +147,7 @@ int ph_socket_work(ph_socket_t *s)
s->rx_header_index = 0;
s->rx_data_index = 0;
/* indicate established socket connection */
ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_REQ, &enable, 1);
s->ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_REQ, &enable, 1);
}
work = 1;
}
@ -169,7 +167,7 @@ int ph_socket_work(ph_socket_t *s)
}
s->connect = rc;
/* connect */
rc = connect(s->connect, (struct sockaddr *)&s->sock_address, SUN_LEN(&s->sock_address));
rc = connect(s->connect, (struct sockaddr *)&s->sock_address, sizeof(s->sock_address));
if (rc < 0 && errno != EAGAIN) {
if (!s->connect_failed)
PDEBUG_CHAN(DPH, DEBUG_NOTICE, "Failed to connect UNIX socket, retrying...\n");
@ -189,7 +187,7 @@ int ph_socket_work(ph_socket_t *s)
s->rx_header_index = 0;
s->rx_data_index = 0;
/* indicate established socket connection */
ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_IND, &enable, 1);
s->ph_socket_rx_msg(s, 0, PH_PRIM_CTRL_IND, &enable, 1);
}
}
}
@ -229,7 +227,7 @@ rx_again:
if (s->rx_msg->msg.header.length)
PDEBUG_CHAN(DPH, DEBUG_DEBUG, " -> data:%s\n", debug_hex(s->rx_msg->msg.data, s->rx_msg->msg.header.length));
}
ph_socket_rx_msg(s, s->rx_msg->msg.header.channel, s->rx_msg->msg.header.prim, s->rx_msg->msg.data, s->rx_msg->msg.header.length);
s->ph_socket_rx_msg(s, s->rx_msg->msg.header.channel, s->rx_msg->msg.header.prim, s->rx_msg->msg.data, s->rx_msg->msg.header.length);
free(s->rx_msg);
s->rx_msg = NULL;
/* reset rx buffer */

@ -89,6 +89,7 @@ struct socket_msg_list {
typedef struct ph_socket {
const char *name;
void (*ph_socket_rx_msg)(struct ph_socket *s, int channel, uint8_t prim, uint8_t *data, int length);
void *priv;
struct sockaddr_un sock_address;
int listen; /* socket to listen to incoming connections */
@ -101,10 +102,9 @@ typedef struct ph_socket {
int rx_data_index;
} ph_socket_t;
int ph_socket_init(ph_socket_t *s, void *priv, const char *socket_name, int server);
int ph_socket_init(ph_socket_t *s, void (*ph_socket_rx_msg)(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length), void *priv, const char *socket_name, int server);
void ph_socket_exit(ph_socket_t *s);
void ph_socket_tx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length);
void ph_socket_rx_msg(ph_socket_t *s, int channel, uint8_t prim, uint8_t *data, int length);
int ph_socket_work(ph_socket_t *s);
Loading…
Cancel
Save