FreeCalypso > hg > themwi-system-sw
diff mncc/mncc_sock.c @ 15:ccc5ab6d8388
first version of themwi-mncc for ThemWi2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 26 Jun 2022 16:31:47 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mncc/mncc_sock.c Sun Jun 26 16:31:47 2022 -0800 @@ -0,0 +1,63 @@ +/* + * In this module we implement low-level handling + * of the main MNCC socket that connects to OsmoMSC. + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <syslog.h> +#include "../include/mncc.h" + +static char mncc_socket_pathname[] = "/var/gsm/mncc_socket"; + +int mncc_socket; + +open_mncc_socket() +{ + struct sockaddr_un sa; + unsigned sa_len; + int rc; + + mncc_socket = socket(AF_UNIX, SOCK_SEQPACKET, 0); + if (mncc_socket < 0) { + syslog(LOG_CRIT, "socket(AF_UNIX, SOCK_SEQPACKET, 0): %m"); + return(-1); + } + fill_sockaddr_un(mncc_socket_pathname, &sa, &sa_len); + rc = connect(mncc_socket, (struct sockaddr *) &sa, sa_len); + if (rc < 0) { + syslog(LOG_ERR, "connect to %s: %m", mncc_socket_pathname); + return(-1); + } + update_max_fd(mncc_socket); + return(0); +} + +void +mncc_socket_select() +{ + union mncc_msg msg; + int rc; + + rc = recv(mncc_socket, &msg, sizeof msg, 0); + if (rc < 0) { + syslog(LOG_CRIT, "error reading from MNCC socket: %m"); + exit(1); + } + if (rc < 4) { + syslog(LOG_CRIT, "short read from MNCC socket: %d bytes", rc); + exit(1); + } + mncc_msg_from_gsm(&msg, rc); +} + +send_mncc_to_gsm(msg, msglen) + union mncc_msg *msg; + unsigned msglen; +{ + return send(mncc_socket, msg, msglen, 0); +}