Commit 43bd996c authored by Yann Garcia's avatar Yann Garcia
Browse files

Add multicast/multigroup support

parent 139f8ad4
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -43,6 +43,8 @@ int32_t parse_params(const int p_argc, char* const p_argv[]);


int32_t parse_config_file(const char* p_config_file);
int32_t parse_config_file(const char* p_config_file);


void free_config_file_resources(void);

char* bin2hex(char* p_hex, size_t p_hlen, const uint8_t* p_bin, size_t p_blen);
char* bin2hex(char* p_hex, size_t p_hlen, const uint8_t* p_bin, size_t p_blen);


void usage(const char* p_progname, const uint8_t p_role);
void usage(const char* p_progname, const uint8_t p_role);
+30 −22
Original line number Original line Diff line number Diff line
@@ -111,12 +111,21 @@ static int32_t web_client_page(struct MHD_Connection *p_connection) {
    "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>"
    "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>"
    "<label for=\"udp_address\">Multicast Address:</label><br>"
    "<label for=\"udp_address\">Multicast Address:</label><br>"
    "<input type=\"text\" id=\"udp_address\" name=\"udp_address\" value=\"%s\"><br>"
    "<input type=\"text\" id=\"udp_address\" name=\"udp_address\" value=\"%s\"><br>"
    "<label for=\"https_port\">Multicqst Port:</label><br>"
    "<label for=\"https_port\">Multicast Port:</label><br>"
    "<input type=\"number\" id=\"udp_port\" name=\"udp_port\" value=\"%d\"><br><br>"
    "<input type=\"number\" id=\"udp_port\" name=\"udp_port\" value=\"%d\"><br><br>"
    "<input type=\"submit\" value=\"Submit\">"
    "<input type=\"submit\" value=\"Submit\">"
    "<input type=\"reset\">"
    "<input type=\"reset\">"
    "</form></body></html>";
    "</form></body></html>";

  /* Load ITS_Bridge_client configuration file */
  free_config_file_resources();
  sprintf(client_config_file, "%s/client.conf", conf_path);
  printf("Parsing file %s.\n", client_config_file);
  if (parse_config_file(client_config_file) == -1) {
    fprintf(stderr, "Failed to parse configuration file %s, exit.\n", config_file);
    return MHD_NO;
  }
  printf("its_nic:%s/%s, IP:%s:%d.\n", its_nic, mac_address, udp_address, udp_port);
  /* Prepare the HTML page to sent to the browser */
  if (buffer != NULL) {
  if (buffer != NULL) {
    free(buffer);
    free(buffer);
  }
  }
@@ -124,6 +133,7 @@ static int32_t web_client_page(struct MHD_Connection *p_connection) {
  buffer = (char*)malloc(size);
  buffer = (char*)malloc(size);
  memset((void*)buffer, 0x00, size);
  memset((void*)buffer, 0x00, size);
  snprintf(buffer, size, page, its_nic, mac_address, udp_nic, udp_address, udp_port);
  snprintf(buffer, size, page, its_nic, mac_address, udp_nic, udp_address, udp_port);
  /* Wait fir the response */
  struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buffer), (void*)(const char*)buffer, MHD_RESPMEM_PERSISTENT);
  struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buffer), (void*)(const char*)buffer, MHD_RESPMEM_PERSISTENT);
  if (!response) {
  if (!response) {
    return MHD_NO;
    return MHD_NO;
@@ -137,8 +147,8 @@ static int32_t web_client_page(struct MHD_Connection *p_connection) {


static int32_t web_server_page(struct MHD_Connection *p_connection) {
static int32_t web_server_page(struct MHD_Connection *p_connection) {
  const char* page =
  const char* page =
    "<!DOCTYPE html><html><body><h2>ITS Bridge Web Confgurator</h2><p>Please enter ETSI ITS_Bridge_client configuration:</p>"
    "<!DOCTYPE html><html><body><h2>ITS Bridge Web Confgurator</h2><p>Please enter ETSI ITS_Bridge_server configuration:</p>"
    "<form action=\"/client_url\" method=\"POST\">"
    "<form action=\"/server_url\" method=\"POST\">"
    "<label for=\"its_nic\">NIC ITS:</label><br>"
    "<label for=\"its_nic\">NIC ITS:</label><br>"
    "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>"
    "<input type=\"text\" id=\"its_nic\" name=\"its_nic\" value=\"%s\"><br>"
    "<label for=\"mac_address\">Mac Address:</label><br>"
    "<label for=\"mac_address\">Mac Address:</label><br>"
@@ -146,13 +156,22 @@ static int32_t web_server_page(struct MHD_Connection *p_connection) {
    "<label for=\"udp_nic\">NIC multicast:</label><br>"
    "<label for=\"udp_nic\">NIC multicast:</label><br>"
    "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>"
    "<input type=\"text\" id=\"udp_nic\" name=\"udp_nic\" value=\"%s\"><br>"
    "<label for=\"udp_address\">Multicast Addresses (Enter multicast address of the other vendors of your session separarated by a semi-colon):</label><br>"
    "<label for=\"udp_address\">Multicast Addresses (Enter multicast address of the other vendors of your session separarated by a semi-colon):</label><br>"
    "<input type=\"text\" id=\"udp_address\" name=\"udp_address\" value=\"%s\"><br>"
    "<input type=\"text\" id=\"udp_address\" name=\"udp_address\" value=\"%s\" size=\"100\"><br>"
    "<label for=\"https_port\">Multicqst Port:</label><br>"
    "<label for=\"https_port\">Multicqst Port:</label><br>"
    "<input type=\"number\" id=\"udp_port\" name=\"udp_port\" value=\"%d\"><br><br>"
    "<input type=\"number\" id=\"udp_port\" name=\"udp_port\" value=\"%d\"><br><br>"
    "<input type=\"submit\" value=\"Submit\">"
    "<input type=\"submit\" value=\"Submit\">"
    "<input type=\"reset\">"
    "<input type=\"reset\">"
    "</form></body></html>";
    "</form></body></html>";

  /* Load ITS_Bridge_server configuration file */
  free_config_file_resources();
  sprintf(server_config_file, "%s/server.conf", conf_path);
  printf("Parsing file %s.\n", server_config_file);
  if (parse_config_file(server_config_file) == -1) {
    fprintf(stderr, "Failed to parse configuration file %s, exit.\n", config_file);
    return MHD_NO;
  }
  printf("its_nic:%s/%s, IP:%s:%d.\n", its_nic, mac_address, udp_address, udp_port);
  /* Prepare the HTML page to sent to the browser */
  if (buffer != NULL) {
  if (buffer != NULL) {
    free(buffer);
    free(buffer);
  }
  }
@@ -160,6 +179,7 @@ static int32_t web_server_page(struct MHD_Connection *p_connection) {
  buffer = (char*)malloc(size);
  buffer = (char*)malloc(size);
  memset((void*)buffer, 0x00, size);
  memset((void*)buffer, 0x00, size);
  snprintf(buffer, size, page, its_nic, mac_address, udp_nic, udp_address, udp_port);
  snprintf(buffer, size, page, its_nic, mac_address, udp_nic, udp_address, udp_port);
  /* Wait fir the response */
  struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buffer), (void*)(const char*)buffer, MHD_RESPMEM_PERSISTENT);
  struct MHD_Response *response = MHD_create_response_from_buffer(strlen(buffer), (void*)(const char*)buffer, MHD_RESPMEM_PERSISTENT);
  if (!response) {
  if (!response) {
    return MHD_NO;
    return MHD_NO;
@@ -466,10 +486,10 @@ static void request_completed(void *cls, struct MHD_Connection *connection,
    } else if (strcmp(con_info->url, "/server_url") == 0) {
    } else if (strcmp(con_info->url, "/server_url") == 0) {
      printf("request_completed: Update server.conf.\n");
      printf("request_completed: Update server.conf.\n");
      /* Create a new one */
      /* Create a new one */
      //save_configuration_file(client_config_file, "server", daemon_mode, 0, "mac_address", mac_address, "its_nic", its_nic, "udp_nic", udp_nic, "udp_address", udp_address, "udp_protocol", "multicast", "udp_port", udp_port, -1);
      //save_configuration_file(server_config_file, "server", daemon_mode, 0, "mac_address", mac_address, "its_nic", its_nic, "udp_nic", udp_nic, "udp_address", udp_address, "udp_protocol", "multicast", "udp_port", udp_port, -1);
      {
      {
        printf("save_configuration_file: its_nic:%s/%s, IP:%s:%s:%d.\n", its_nic, mac_address, udp_nic, udp_address, udp_port);
        printf("save_configuration_file: its_nic:%s/%s, IP:%s:%s:%d.\n", its_nic, mac_address, udp_nic, udp_address, udp_port);
        FILE* fp = fopen(client_config_file, "w");
        FILE* fp = fopen(server_config_file, "w");
        if (fp == NULL) {
        if (fp == NULL) {
          goto end;
          goto end;
        }
        }
@@ -554,16 +574,6 @@ int32_t main(const int32_t p_argc, char* const p_argv[]) {
  }
  }
  printf("realm=%s, login=%s:%s, pem=%s, key=%s, conf_path=%s.\n", realm, login, password, cert_pem, cert_key, conf_path);
  printf("realm=%s, login=%s:%s, pem=%s, key=%s, conf_path=%s.\n", realm, login, password, cert_pem, cert_key, conf_path);


  /* Load ITS_Bridge_client configuration file */
  sprintf(client_config_file, "%s/client.conf", conf_path);
  printf("Parsing file %s.\n", client_config_file);
  if (parse_config_file(client_config_file) == -1) {
    fprintf(stderr, "Failed to parse configuration file %s, exit.\n", config_file);
    goto error;
  }
  printf("its_nic:%s/%s, IP:%s:%d.\n", its_nic, mac_address, udp_address, udp_port);
  /* Load ITS_Bridge_server configuration file */

  /* Daemonize */
  /* Daemonize */
  if (daemonized) {
  if (daemonized) {
    daemonize();
    daemonize();
@@ -631,10 +641,7 @@ int32_t main(const int32_t p_argc, char* const p_argv[]) {
      free(cert_key);
      free(cert_key);
    }
    }


    free(its_nic);
    free_config_file_resources();
    free(mac_address);
    free(udp_nic);
    free(udp_address);


    if (state == _reload) {
    if (state == _reload) {
      if (parse_config_file(config_file) == -1) {
      if (parse_config_file(config_file) == -1) {
@@ -648,6 +655,7 @@ int32_t main(const int32_t p_argc, char* const p_argv[]) {


  return 0;
  return 0;
 error:
 error:
  free_config_file_resources();
  if (buffer != NULL) {
  if (buffer != NULL) {
    free(buffer);
    free(buffer);
  }
  }
+26 −2
Original line number Original line Diff line number Diff line
@@ -141,6 +141,30 @@ int32_t parse_config_file(const char* p_config_file) {
  return 0;
  return 0;
}
}


void free_config_file_resources() {
  if (mac_address != NULL) {
    free(mac_address);
    mac_address = NULL;
  }
  if (its_nic != NULL) {
    free(its_nic);
    its_nic = NULL;
  }
  if (udp_nic != NULL) {
    free(udp_nic);
    udp_nic = NULL;
  }
  if (udp_address != NULL) {
    free(udp_address);
    udp_address = NULL;
  }
  if (udp_protocol != NULL) {
    free(udp_protocol);
    udp_protocol = NULL;
  }
  udp_port = 0;
}

char* bin2hex(char* p_hex, size_t p_hlen, const uint8_t* p_bin, size_t p_blen) {
char* bin2hex(char* p_hex, size_t p_hlen, const uint8_t* p_bin, size_t p_blen) {
  static const char* _hexDigits = "0123456789ABCDEF";
  static const char* _hexDigits = "0123456789ABCDEF";
	const uint8_t *b, *e;
	const uint8_t *b, *e;
@@ -435,7 +459,7 @@ char** str_split(const char* p_string, const char p_separator) {


  /* Count how many elements will be extracted */
  /* Count how many elements will be extracted */
  size_t count = 0;
  size_t count = 0;
  char* current = p_string;
  char* current = (char*)p_string;
  char* previous = NULL;
  char* previous = NULL;
  while (*current != 0x00) {
  while (*current != 0x00) {
    if (p_separator == *current) {
    if (p_separator == *current) {