예제 #1
0
/****************************************************************************
 **                                                                        **
 ** Name:  network_api_send_data()                                   **
 **                                                                        **
 ** Description: Send data to the network sublayer                         **
 **                                                                        **
 ** Inputs:  fd:    File descriptor of the connection endpoint **
 **       to which data have to be sent              **
 **      length:  Number of bytes to send                    **
 **      Others:  _network_api_send_buffer, _network_api_id  **
 **                                                                        **
 ** Outputs:   Return:  The number of bytes sent when success;     **
 **       RETURNerror otherwise                      **
 **      Others:  None                                       **
 **                                                                        **
 ***************************************************************************/
int network_api_send_data(int fd, int length)
{
  LOG_FUNC_IN;

  int sbytes;

  /* Sanity check */
  int sfd = network_api_get_fd();

  if (fd != sfd) {
    LOG_TRACE(ERROR, "NET-API   - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
    LOG_FUNC_RETURN (RETURNerror);
  }

  /* Send data to the network sublayer */
  sbytes = NETWORK_API_SEND(_network_api_send_buffer, length);

  if (sbytes == RETURNerror) {
    LOG_TRACE(ERROR, "NET-API   - send() failed, %s", strerror(errno));
    LOG_FUNC_RETURN (RETURNerror);
  } else if (sbytes == 0) {
    LOG_TRACE(WARNING, "NET-API   - A signal was caught");
  } else {
    LOG_TRACE(INFO, "NET-API   - %d bytes sent to the network sublayer",
              sbytes);
    LOG_DUMP(_network_api_send_buffer, sbytes);
  }

  LOG_FUNC_RETURN (sbytes);
}
예제 #2
0
/****************************************************************************
 **                                                                        **
 ** Name:  network_api_initialize()                                  **
 **                                                                        **
 ** Description: Initializes the network API from which the NAS layer      **
 **    will send/receive messages to/from the network sublayer   **
 **                                                                        **
 ** Inputs:  host:    The name of the host from which the net-   **
 **       work sublayer will connect                 **
 **      port:    The local port number                      **
 **      Others:  None                                       **
 **                                                                        **
 ** Outputs:   Return:  RETURNerror, RETURNok                      **
 **      Others:  _network_api_id                            **
 **                                                                        **
 ***************************************************************************/
int network_api_initialize(const char* host, const char* port)
{
  LOG_FUNC_IN;

  /* Initialize network socket handlers */
  _network_api_id.open  = socket_udp_open;
  _network_api_id.getfd = socket_get_fd;
  _network_api_id.recv  = socket_recv;
  _network_api_id.send  = socket_send;
  _network_api_id.close = socket_close;
  /* Initialize UDP communication channel with the network layer */
#ifdef NAS_UE
  _network_api_id.endpoint = NETWORK_API_OPEN(SOCKET_CLIENT, host, port);
#endif
#ifdef NAS_MME
  _network_api_id.endpoint = NETWORK_API_OPEN(SOCKET_SERVER, NULL, port);
#endif

  if (_network_api_id.endpoint == NULL) {
    const char* error = ( (errno < 0) ?
                          gai_strerror(errno) : strerror(errno) );
    LOG_TRACE(ERROR, "NET-API   - Failed to open connection endpoint, %s",
              error);
    LOG_FUNC_RETURN (RETURNerror);
  }

  gethostname(_network_api_send_buffer, NETWORK_API_SEND_BUFFER_SIZE);
  LOG_TRACE(INFO, "NET-API   - Network's UDP socket %d is BOUND to %s/%s",
            network_api_get_fd(), _network_api_send_buffer, port);

  LOG_FUNC_RETURN (RETURNok);
}
예제 #3
0
/****************************************************************************
 **                                                                        **
 ** Name:  network_api_read_data()                                   **
 **                                                                        **
 ** Description: Read data received from the network sublayer              **
 **                                                                        **
 ** Inputs:  fd:    File descriptor of the connection endpoint **
 **       from which data have been received         **
 **      Others:  _network_api_id                            **
 **                                                                        **
 ** Outputs:   Return:  The number of bytes read when success;     **
 **       RETURNerror otherwise                      **
 **      Others:  _network_api_recv_buffer, _network_api_id  **
 **                                                                        **
 ***************************************************************************/
int network_api_read_data(int fd)
{
  LOG_FUNC_IN;

  int rbytes;

  /* Sanity check */
  int sfd = network_api_get_fd();

  if (fd != sfd) {
    LOG_TRACE(ERROR, "NET-API   - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
    LOG_FUNC_RETURN (RETURNerror);
  }

  memset(_network_api_recv_buffer, 0, NETWORK_API_RECV_BUFFER_SIZE);

  /* Receive data from the network sublayer */
  rbytes = NETWORK_API_RECV(_network_api_recv_buffer,
                            NETWORK_API_RECV_BUFFER_SIZE);

  if (rbytes == RETURNerror) {
    LOG_TRACE(ERROR, "NET-API   - recv() failed, %s", strerror(errno));
    LOG_FUNC_RETURN (RETURNerror);
  } else if (rbytes == 0) {
    LOG_TRACE(WARNING, "NET-API   - A signal was caught");
  } else {
    LOG_TRACE(INFO, "NET-API   - %d bytes received from the network "
              "sublayer", rbytes);
    LOG_DUMP(_network_api_recv_buffer, rbytes);
  }

  LOG_FUNC_RETURN (rbytes);
}
예제 #4
0
/****************************************************************************
 **                                                                        **
 ** Name:  as_message_send()                                         **
 **                                                                        **
 ** Description: Service provided to the EPS Mobility Management protocol  **
 **    at the EMMAS Access Point (EMMAS-SAP) to send AS messages **
 **    to the Access Stratum sublayer.                           **
 **                                                                        **
 ** Inputs:  as_msg:  The AS message to send                     **
 **      Others:  _network_api_send_buffer, _network_api_id  **
 **                                                                        **
 ** Outputs:   Return:  The number of bytes sent when success;     **
 **       RETURNerror Otherwise                      **
 **      Others:  _network_api_send_buffer                   **
 **                                                                        **
 ***************************************************************************/
int
as_message_send (
  as_message_t * as_msg)
{
  int                                     bytes;

  LOG_FUNC_IN;
  LOG_TRACE (INFO, "NET-API   - Send message 0x%.4x to the Access Stratum " "layer", as_msg->msgID);
  /*
   * Encode the AS message
   */
  bytes = network_api_encode_data (as_msg);

  if (bytes > 0) {
    /*
     * Get the network file descriptor
     */
    int                                     fd = network_api_get_fd ();

    if (fd != RETURNerror) {
      /*
       * Send the AS message to the network
       */
      bytes = network_api_send_data (fd, bytes);
    }
  }

  LOG_FUNC_RETURN (bytes);
}
예제 #5
0
/****************************************************************************
 **                                                                        **
 ** Name:  network_api_close()                                       **
 **                                                                        **
 ** Description: Clean the network API from which the NAS layer sent/recei-**
 **    ved messages to/from the network sublayer                 **
 **                                                                        **
 ** Inputs:  fd:    File descriptor of the connection endpoint **
 **       allocated by the system to communicate     **
 **       with the network sublayer                  **
 **      Others:  None                                       **
 **                                                                        **
 ** Outputs:   Return:  None                                       **
 **      Others:  _network_api_id                            **
 **                                                                        **
 ***************************************************************************/
void network_api_close(int fd)
{
  LOG_FUNC_IN;

  /* Sanity check */
  int sfd = network_api_get_fd();

  if (fd != sfd) {
    LOG_TRACE(ERROR, "NET-API   - Endpoint %d is not the one created for communication with the network sublayer (%d)", fd, sfd);
    LOG_FUNC_OUT;
    return;
  }

  /* Cleanup the connection endpoint */
  NETWORK_API_CLOSE();
  _network_api_id.endpoint = NULL;

  LOG_FUNC_OUT;
}