Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 1 | /* GSMTAP support code in libmsomcore */ |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 2 | /* |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 3 | * (C) 2010-2011 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include "../config.h" |
| 24 | |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 25 | #include <osmocom/core/gsmtap_util.h> |
| 26 | #include <osmocom/core/logging.h> |
| 27 | #include <osmocom/core/gsmtap.h> |
| 28 | #include <osmocom/core/msgb.h> |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 29 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 30 | #include <osmocom/core/select.h> |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 31 | #include <osmocom/core/socket.h> |
Pablo Neira Ayuso | 8341934 | 2011-03-22 16:36:13 +0100 | [diff] [blame] | 32 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
| 33 | #include <osmocom/gsm/rsl.h> |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 34 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 35 | #include <sys/types.h> |
Harald Welte | e476442 | 2011-05-22 12:25:57 +0200 | [diff] [blame] | 36 | |
| 37 | #include <arpa/inet.h> |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 38 | |
| 39 | #include <stdio.h> |
| 40 | #include <unistd.h> |
| 41 | #include <stdint.h> |
| 42 | #include <string.h> |
| 43 | #include <errno.h> |
| 44 | |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 45 | /*! \addtogroup gsmtap |
| 46 | * @{ |
| 47 | */ |
| 48 | /*! \file gsmtap_util.c */ |
| 49 | |
| 50 | |
| 51 | /*! \brief convert RSL channel number to GSMTAP channel type |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 52 | * \param[in] rsl_chantype RSL channel type |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 53 | * \param[in] link_id RSL link identifier |
| 54 | * \returns GSMTAP channel type |
| 55 | */ |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 56 | uint8_t chantype_rsl2gsmtap(uint8_t rsl_chantype, uint8_t link_id) |
| 57 | { |
| 58 | uint8_t ret = GSMTAP_CHANNEL_UNKNOWN; |
| 59 | |
| 60 | switch (rsl_chantype) { |
| 61 | case RSL_CHAN_Bm_ACCHs: |
| 62 | ret = GSMTAP_CHANNEL_TCH_F; |
| 63 | break; |
| 64 | case RSL_CHAN_Lm_ACCHs: |
| 65 | ret = GSMTAP_CHANNEL_TCH_H; |
| 66 | break; |
| 67 | case RSL_CHAN_SDCCH4_ACCH: |
| 68 | ret = GSMTAP_CHANNEL_SDCCH4; |
| 69 | break; |
| 70 | case RSL_CHAN_SDCCH8_ACCH: |
| 71 | ret = GSMTAP_CHANNEL_SDCCH8; |
| 72 | break; |
| 73 | case RSL_CHAN_BCCH: |
| 74 | ret = GSMTAP_CHANNEL_BCCH; |
| 75 | break; |
| 76 | case RSL_CHAN_RACH: |
| 77 | ret = GSMTAP_CHANNEL_RACH; |
| 78 | break; |
| 79 | case RSL_CHAN_PCH_AGCH: |
| 80 | /* it could also be AGCH... */ |
| 81 | ret = GSMTAP_CHANNEL_PCH; |
| 82 | break; |
| 83 | } |
| 84 | |
| 85 | if (link_id & 0x40) |
| 86 | ret |= GSMTAP_CHANNEL_ACCH; |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
Sylvain Munaut | abf66e7 | 2011-09-26 13:23:19 +0200 | [diff] [blame] | 91 | /*! \brief create an arbitrary type GSMTAP message |
| 92 | * \param[in] type The GSMTAP_TYPE_xxx constant of the message to create |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 93 | * \param[in] arfcn GSM ARFCN (Channel Number) |
| 94 | * \param[in] ts GSM time slot |
| 95 | * \param[in] chan_type Channel Type |
| 96 | * \param[in] ss Sub-slot |
| 97 | * \param[in] fn GSM Frame Number |
| 98 | * \param[in] signal_dbm Signal Strength (dBm) |
| 99 | * \param[in] snr Signal/Noise Ratio (SNR) |
| 100 | * \param[in] data Pointer to data buffer |
| 101 | * \param[in] len Length of \ref data |
| 102 | * |
| 103 | * This function will allocate a new msgb and fill it with a GSMTAP |
| 104 | * header containing the information |
| 105 | */ |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 106 | struct msgb *gsmtap_makemsg_ex(uint8_t type, uint16_t arfcn, uint8_t ts, uint8_t chan_type, |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 107 | uint8_t ss, uint32_t fn, int8_t signal_dbm, |
| 108 | uint8_t snr, const uint8_t *data, unsigned int len) |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 109 | { |
| 110 | struct msgb *msg; |
| 111 | struct gsmtap_hdr *gh; |
| 112 | uint8_t *dst; |
| 113 | |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 114 | msg = msgb_alloc(sizeof(*gh) + len, "gsmtap_tx"); |
| 115 | if (!msg) |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 116 | return NULL; |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 117 | |
| 118 | gh = (struct gsmtap_hdr *) msgb_put(msg, sizeof(*gh)); |
| 119 | |
| 120 | gh->version = GSMTAP_VERSION; |
| 121 | gh->hdr_len = sizeof(*gh)/4; |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 122 | gh->type = type; |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 123 | gh->timeslot = ts; |
| 124 | gh->sub_slot = ss; |
| 125 | gh->arfcn = htons(arfcn); |
| 126 | gh->snr_db = snr; |
| 127 | gh->signal_dbm = signal_dbm; |
| 128 | gh->frame_number = htonl(fn); |
| 129 | gh->sub_type = chan_type; |
| 130 | gh->antenna_nr = 0; |
| 131 | |
| 132 | dst = msgb_put(msg, len); |
| 133 | memcpy(dst, data, len); |
| 134 | |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 135 | return msg; |
| 136 | } |
| 137 | |
Sylvain Munaut | abf66e7 | 2011-09-26 13:23:19 +0200 | [diff] [blame] | 138 | /*! \brief create L1/L2 data and put it into GSMTAP |
| 139 | * \param[in] arfcn GSM ARFCN (Channel Number) |
| 140 | * \param[in] ts GSM time slot |
| 141 | * \param[in] chan_type Channel Type |
| 142 | * \param[in] ss Sub-slot |
| 143 | * \param[in] fn GSM Frame Number |
| 144 | * \param[in] signal_dbm Signal Strength (dBm) |
| 145 | * \param[in] snr Signal/Noise Ratio (SNR) |
| 146 | * \param[in] data Pointer to data buffer |
| 147 | * \param[in] len Length of \ref data |
| 148 | * |
| 149 | * This function will allocate a new msgb and fill it with a GSMTAP |
| 150 | * header containing the information |
| 151 | */ |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 152 | struct msgb *gsmtap_makemsg(uint16_t arfcn, uint8_t ts, uint8_t chan_type, |
| 153 | uint8_t ss, uint32_t fn, int8_t signal_dbm, |
| 154 | uint8_t snr, const uint8_t *data, unsigned int len) |
| 155 | { |
| 156 | return gsmtap_makemsg_ex(GSMTAP_TYPE_UM, arfcn, ts, chan_type, |
| 157 | ss, fn, signal_dbm, snr, data, len); |
| 158 | } |
| 159 | |
Harald Welte | e476442 | 2011-05-22 12:25:57 +0200 | [diff] [blame] | 160 | #ifdef HAVE_SYS_SOCKET_H |
| 161 | |
| 162 | #include <sys/socket.h> |
| 163 | #include <netinet/in.h> |
| 164 | |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 165 | /*! \brief Create a new (sending) GSMTAP source socket |
| 166 | * \param[in] host host name or IP address in string format |
| 167 | * \param[in] port UDP port number in host byte order |
| 168 | * |
| 169 | * Opens a GSMTAP source (sending) socket, conncet it to host/port and |
| 170 | * return resulting fd. If \a host is NULL, the destination address |
| 171 | * will be localhost. If \a port is 0, the default \ref |
| 172 | * GSMTAP_UDP_PORT will be used. |
| 173 | * */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 174 | int gsmtap_source_init_fd(const char *host, uint16_t port) |
| 175 | { |
| 176 | if (port == 0) |
| 177 | port = GSMTAP_UDP_PORT; |
| 178 | if (host == NULL) |
| 179 | host = "localhost"; |
| 180 | |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 181 | return osmo_sock_init(AF_UNSPEC, SOCK_DGRAM, IPPROTO_UDP, host, port, |
| 182 | OSMO_SOCK_F_CONNECT); |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 185 | /*! \brief Add a local sink to an existing GSMTAP source and return fd |
| 186 | * \param[in] gsmtap_fd file descriptor of the gsmtap socket |
| 187 | * \returns file descriptor of locally bound receive socket |
| 188 | * |
| 189 | * In case the GSMTAP socket is connected to a local destination |
| 190 | * IP/port, this function creates a corresponding receiving socket |
| 191 | * bound to that destination IP + port. |
| 192 | * |
| 193 | * In case the gsmtap socket is not connected to a local IP/port, or |
| 194 | * creation of the receiving socket fails, a negative error code is |
| 195 | * returned. |
| 196 | */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 197 | int gsmtap_source_add_sink_fd(int gsmtap_fd) |
| 198 | { |
| 199 | struct sockaddr_storage ss; |
| 200 | socklen_t ss_len = sizeof(ss); |
| 201 | int rc; |
| 202 | |
| 203 | rc = getpeername(gsmtap_fd, (struct sockaddr *)&ss, &ss_len); |
| 204 | if (rc < 0) |
| 205 | return rc; |
| 206 | |
| 207 | if (osmo_sockaddr_is_local((struct sockaddr *)&ss, ss_len) == 1) { |
Pablo Neira Ayuso | 0849c9a | 2011-06-09 15:04:30 +0200 | [diff] [blame] | 208 | rc = osmo_sock_init_sa((struct sockaddr *)&ss, SOCK_DGRAM, |
| 209 | IPPROTO_UDP, OSMO_SOCK_F_BIND); |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 210 | if (rc >= 0) |
| 211 | return rc; |
| 212 | } |
| 213 | |
| 214 | return -ENODEV; |
| 215 | } |
| 216 | |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 217 | /*! \brief Send a \ref msgb through a GSMTAP source |
| 218 | * \param[in] gti GSMTAP instance |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 219 | * \param[in] msg message buffer |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 220 | */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 221 | int gsmtap_sendmsg(struct gsmtap_inst *gti, struct msgb *msg) |
| 222 | { |
Harald Welte | 13692a6 | 2011-05-22 20:06:11 +0200 | [diff] [blame] | 223 | if (!gti) |
| 224 | return -ENODEV; |
| 225 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 226 | if (gti->ofd_wq_mode) |
| 227 | return osmo_wqueue_enqueue(>i->wq, msg); |
| 228 | else { |
| 229 | /* try immediate send and return error if any */ |
| 230 | int rc; |
| 231 | |
| 232 | rc = write(gsmtap_inst_fd(gti), msg->data, msg->len); |
| 233 | if (rc <= 0) { |
| 234 | return rc; |
| 235 | } else if (rc >= msg->len) { |
| 236 | msgb_free(msg); |
| 237 | return 0; |
| 238 | } else { |
| 239 | /* short write */ |
| 240 | return -EIO; |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
Sylvain Munaut | abf66e7 | 2011-09-26 13:23:19 +0200 | [diff] [blame] | 245 | /*! \brief send an arbitrary type through GSMTAP. |
| 246 | * See \ref gsmtap_makemsg_ex for arguments |
| 247 | */ |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 248 | int gsmtap_send_ex(struct gsmtap_inst *gti, uint8_t type, uint16_t arfcn, uint8_t ts, |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 249 | uint8_t chan_type, uint8_t ss, uint32_t fn, |
| 250 | int8_t signal_dbm, uint8_t snr, const uint8_t *data, |
| 251 | unsigned int len) |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 252 | { |
| 253 | struct msgb *msg; |
| 254 | |
Harald Welte | 13692a6 | 2011-05-22 20:06:11 +0200 | [diff] [blame] | 255 | if (!gti) |
| 256 | return -ENODEV; |
| 257 | |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 258 | msg = gsmtap_makemsg_ex(type, arfcn, ts, chan_type, ss, fn, signal_dbm, |
Harald Welte | e34a940 | 2010-06-29 22:31:21 +0200 | [diff] [blame] | 259 | snr, data, len); |
| 260 | if (!msg) |
| 261 | return -ENOMEM; |
| 262 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 263 | return gsmtap_sendmsg(gti, msg); |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Sylvain Munaut | abf66e7 | 2011-09-26 13:23:19 +0200 | [diff] [blame] | 266 | /*! \brief send a message from L1/L2 through GSMTAP. |
| 267 | * See \ref gsmtap_makemsg for arguments |
| 268 | */ |
Sylvain Munaut | 15ae715 | 2011-09-26 13:05:07 +0200 | [diff] [blame] | 269 | int gsmtap_send(struct gsmtap_inst *gti, uint16_t arfcn, uint8_t ts, |
| 270 | uint8_t chan_type, uint8_t ss, uint32_t fn, |
| 271 | int8_t signal_dbm, uint8_t snr, const uint8_t *data, |
| 272 | unsigned int len) |
| 273 | { |
| 274 | return gsmtap_send_ex(gti, GSMTAP_TYPE_UM, arfcn, ts, chan_type, ss, fn, |
| 275 | signal_dbm, snr, data, len); |
| 276 | } |
| 277 | |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 278 | /* Callback from select layer if we can write to the socket */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 279 | static int gsmtap_wq_w_cb(struct osmo_fd *ofd, struct msgb *msg) |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 280 | { |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 281 | int rc; |
| 282 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 283 | rc = write(ofd->fd, msg->data, msg->len); |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 284 | if (rc < 0) { |
| 285 | perror("writing msgb to gsmtap fd"); |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 286 | return rc; |
| 287 | } |
| 288 | if (rc != msg->len) { |
| 289 | perror("short write to gsmtap fd"); |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 290 | return -EIO; |
| 291 | } |
| 292 | |
Harald Welte | e779c36 | 2010-06-29 20:51:13 +0200 | [diff] [blame] | 293 | return 0; |
| 294 | } |
| 295 | |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 296 | /* Callback from select layer if we can read from the sink socket */ |
Pablo Neira Ayuso | f7f89d0 | 2011-05-07 12:42:40 +0200 | [diff] [blame] | 297 | static int gsmtap_sink_fd_cb(struct osmo_fd *fd, unsigned int flags) |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 298 | { |
| 299 | int rc; |
| 300 | uint8_t buf[4096]; |
| 301 | |
| 302 | if (!(flags & BSC_FD_READ)) |
| 303 | return 0; |
| 304 | |
| 305 | rc = read(fd->fd, buf, sizeof(buf)); |
| 306 | if (rc < 0) { |
| 307 | perror("reading from gsmtap sink fd"); |
| 308 | return rc; |
| 309 | } |
| 310 | /* simply discard any data arriving on the socket */ |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 315 | /*! \brief Add a local sink to an existing GSMTAP source instance */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 316 | int gsmtap_source_add_sink(struct gsmtap_inst *gti) |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 317 | { |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 318 | int fd; |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 319 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 320 | fd = gsmtap_source_add_sink_fd(gsmtap_inst_fd(gti)); |
| 321 | if (fd < 0) |
| 322 | return fd; |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 323 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 324 | if (gti->ofd_wq_mode) { |
| 325 | struct osmo_fd *sink_ofd; |
| 326 | |
| 327 | sink_ofd = >i->sink_ofd; |
| 328 | sink_ofd->fd = fd; |
| 329 | sink_ofd->when = BSC_FD_READ; |
| 330 | sink_ofd->cb = gsmtap_sink_fd_cb; |
| 331 | |
| 332 | osmo_fd_register(sink_ofd); |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 335 | return fd; |
| 336 | } |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 337 | |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 338 | |
| 339 | /*! \brief Open GSMTAP source socket, connect and register osmo_fd |
| 340 | * \param[in] host host name or IP address in string format |
| 341 | * \param[in] port UDP port number in host byte order |
Katerina Barone-Adesi | c28c6a0 | 2013-02-15 13:27:59 +0100 | [diff] [blame] | 342 | * \param[in] ofd_wq_mode Register \ref osmo_wqueue (1) or not (0) |
Harald Welte | 47379ca | 2011-08-17 16:35:24 +0200 | [diff] [blame] | 343 | * |
| 344 | * Open GSMTAP source (sending) socket, connect it to host/port, |
| 345 | * allocate 'struct gsmtap_inst' and optionally osmo_fd/osmo_wqueue |
| 346 | * registration. This means it is like \ref gsmtap_init2 but integrated |
| 347 | * with libosmocore \ref select */ |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 348 | struct gsmtap_inst *gsmtap_source_init(const char *host, uint16_t port, |
| 349 | int ofd_wq_mode) |
| 350 | { |
| 351 | struct gsmtap_inst *gti; |
| 352 | int fd; |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 353 | |
Harald Welte | 33cb71a | 2011-05-21 18:54:32 +0200 | [diff] [blame] | 354 | fd = gsmtap_source_init_fd(host, port); |
| 355 | if (fd < 0) |
| 356 | return NULL; |
| 357 | |
| 358 | gti = talloc_zero(NULL, struct gsmtap_inst); |
| 359 | gti->ofd_wq_mode = ofd_wq_mode; |
| 360 | gti->wq.bfd.fd = fd; |
| 361 | gti->sink_ofd.fd = -1; |
| 362 | |
| 363 | if (ofd_wq_mode) { |
| 364 | osmo_wqueue_init(>i->wq, 64); |
| 365 | gti->wq.write_cb = &gsmtap_wq_w_cb; |
| 366 | |
| 367 | osmo_fd_register(>i->wq.bfd); |
| 368 | } |
| 369 | |
| 370 | return gti; |
Harald Welte | d58ba46 | 2011-04-27 10:57:49 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Harald Welte | e476442 | 2011-05-22 12:25:57 +0200 | [diff] [blame] | 373 | #endif /* HAVE_SYS_SOCKET_H */ |
Harald Welte | de6e498 | 2012-12-06 21:25:27 +0100 | [diff] [blame] | 374 | |
| 375 | /*! @} */ |