Exemple #1
0
void ieee802_11_mgmt(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype)
{
    struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) buf;

    if (stype == WLAN_FC_STYPE_BEACON) {
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_EXCESSIVE, "mgmt::beacon\n");
        handle_beacon(hapd, mgmt, len);
        return;
    }

    if (memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0 &&
            (hapd->assoc_ap_state == DO_NOT_ASSOC ||
             memcmp(mgmt->bssid, hapd->conf->assoc_ap_addr, ETH_ALEN) != 0)) {
        printf("MGMT: BSSID=" MACSTR " not our address\n",
               MAC2STR(mgmt->bssid));
        return;
    }


    if (stype == WLAN_FC_STYPE_PROBE_REQ) {
        printf("mgmt::probe_req\n");
        return;
    }

    if (memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
        printf("MGMT: DA=" MACSTR " not our address\n",
               MAC2STR(mgmt->da));
        return;
    }

    switch (stype) {
    case WLAN_FC_STYPE_AUTH:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::auth\n");
        handle_auth(hapd, mgmt, len);
        break;
    case WLAN_FC_STYPE_ASSOC_REQ:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::assoc_req\n");
        handle_assoc(hapd, mgmt, len, 0);
        break;
    case WLAN_FC_STYPE_ASSOC_RESP:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::assoc_resp\n");
        handle_assoc_resp(hapd, mgmt, len);
        break;
    case WLAN_FC_STYPE_REASSOC_REQ:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::reassoc_req\n");
        handle_assoc(hapd, mgmt, len, 1);
        break;
    case WLAN_FC_STYPE_DISASSOC:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::disassoc\n");
        handle_disassoc(hapd, mgmt, len);
        break;
    case WLAN_FC_STYPE_DEAUTH:
        HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "mgmt::deauth\n");
        handle_deauth(hapd, mgmt, len);
        break;
    default:
        printf("unknown mgmt frame subtype %d\n", stype);
        break;
    }
}
static int
mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh,
    const u_char *p, u_int length)
{
	switch (FC_SUBTYPE(fc)) {
	case ST_ASSOC_REQUEST:
		printf("Assoc Request");
		return handle_assoc_request(p, length);
	case ST_ASSOC_RESPONSE:
		printf("Assoc Response");
		return handle_assoc_response(p, length);
	case ST_REASSOC_REQUEST:
		printf("ReAssoc Request");
		return handle_reassoc_request(p, length);
	case ST_REASSOC_RESPONSE:
		printf("ReAssoc Response");
		return handle_reassoc_response(p, length);
	case ST_PROBE_REQUEST:
		printf("Probe Request");
		return handle_probe_request(p, length);
	case ST_PROBE_RESPONSE:
		printf("Probe Response");
		return handle_probe_response(p, length);
	case ST_BEACON:
		printf("Beacon");
		return handle_beacon(p, length);
	case ST_ATIM:
		printf("ATIM");
		return handle_atim();
	case ST_DISASSOC:
		printf("Disassociation");
		return handle_disassoc(p, length);
	case ST_AUTH:
		printf("Authentication");
		if (!TTEST2(*p, 3))
			return 0;
		if ((p[0] == 0 ) && (p[1] == 0) && (p[2] == 0)) {
			printf("Authentication (Shared-Key)-3 ");
			return wep_print(p);
		}
		return handle_auth(p, length);
	case ST_DEAUTH:
		printf("DeAuthentication");
		return handle_deauth(pmh, p, length);
		break;
	case ST_ACTION:
		printf("Action");
		return handle_action(pmh, p, length);
		break;
	default:
		printf("Unhandled Management subtype(%x)",
		    FC_SUBTYPE(fc));
		return 1;
	}
}
Exemple #3
0
// Handle's a client's request
// @param connectionfd the descriptor for the connection
// @param server the database server
// @param command the type of request
// @param client the client's information
// @return 1 if the server should handle another request, -1 otherwise
int handle_request(int connectionfd, char *server, char **command, client_info **client) {
    
    // Check if the client used the correct protocol
    if (read_request(connectionfd, &(*client)->username, &(*client)->password, &(*client)->token, &(*client)->list, command) == 1) {
        
        // The client sent an 'Auth' request
        if (strcmp(*command, COMMAND_AUTH) == 0) {
            
            // Attempt to authenticate the client with the Hooli database
            if (handle_auth(connectionfd, server, command, &(*client)->username, &(*client)->password) == -1) {
                
                return -1;
                
            } //end if
            
        } //end if
        
        // The client sent a 'List' request
        else if (strcmp(*command, COMMAND_LIST) == 0) {
            
            // Attempt to sync the client with the Hooli database
            if (handle_list(connectionfd, server, command, &(*client)->token,
                            &(*client)->response_list, (*client)->list) == -1) {
                
                return -1;
                
            } //end if
            
        } //end else if
        
        // The client gave an invalid command
        else {
            
            syslog(LOG_DEBUG, "Expected valid command, got '%s'", *command);
            response_401(connectionfd);
            return -1;
            
        } //end else
        
    } //end if
    
    // The client's message did not follow the protocol
    else {
        
        syslog(LOG_DEBUG, "Received message failed to follow protocol");
        response_401(connectionfd);
        return -1;
        
    } //end else
    
    return 1;
    
} //end handle_request
static void
parse_username_password(struct vsf_session* p_sess)
{
  while (1)
  {
    /* Kitsune: update point */
		kitsune_update("prelogin.c"); /**DSU updatepoint */
    /* Kitsune */  
    vsf_sysutil_kitsune_set_update_point("prelogin.c");    

    vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str,
                              &p_sess->ftp_arg_str, 1);
    if (str_equal_text(&p_sess->ftp_cmd_str, "USER"))
    {
      handle_user_command(p_sess);
    }
    else if (str_equal_text(&p_sess->ftp_cmd_str, "PASS"))
    {
      handle_pass_command(p_sess);
    }
    else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT"))
    {
      vsf_cmdio_write(p_sess, FTP_GOODBYE, "Goodbye.");
      vsf_sysutil_exit(0);
    }
    else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT"))
    {
      handle_feat(p_sess);
    }
    else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "AUTH"))
    {
      handle_auth(p_sess);
    }
    else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PBSZ"))
    {
      handle_pbsz(p_sess);
    }
    else if (tunable_ssl_enable && str_equal_text(&p_sess->ftp_cmd_str, "PROT"))
    {
      handle_prot(p_sess);
    }
    else
    {
      vsf_cmdio_write(p_sess, FTP_LOGINERR,
                      "Please login with USER and PASS.");
    }
  }
}
Exemple #5
0
static int
mgmt_body_print(u_int16_t fc, const struct mgmt_header_t *pmh,
    const u_char *p)
{
	printf("%s", subtype_text[FC_SUBTYPE(fc)]);

	switch (FC_SUBTYPE(fc)) {
	case ST_ASSOC_REQUEST:
		return handle_assoc_request(p);
	case ST_ASSOC_RESPONSE:
		return handle_assoc_response(p);
	case ST_REASSOC_REQUEST:
		return handle_reassoc_request(p);
	case ST_REASSOC_RESPONSE:
		return handle_reassoc_response(p);
	case ST_PROBE_REQUEST:
		return handle_probe_request(p);
	case ST_PROBE_RESPONSE:
		return handle_probe_response(p);
	case ST_BEACON:
		return handle_beacon(p);
	case ST_ATIM:
		return handle_atim();
	case ST_DISASSOC:
		return handle_disassoc(p);
	case ST_AUTH:
		if (!TTEST2(*p, 3))
			return 0;
		if ((p[0] == 0 ) && (p[1] == 0) && (p[2] == 0)) {
			printf("Authentication (Shared-Key)-3 ");
			return wep_print(p);
		}
		return handle_auth(p);
	case ST_DEAUTH:
		return handle_deauth(pmh, p);
		break;
	default:
		printf("Unhandled Management subtype(%x)",
		    FC_SUBTYPE(fc));
		return 1;
	}
}
Exemple #6
0
void handle_command(char *buf, int buf_len)
{
  if (buf_len >= 1)
  {
    char cmd = *buf;
    buf++; buf_len--;
    switch (cmd)
    {
      case CMD_AUTH:
        handle_auth(buf, buf_len);
        break;
      case CMD_NEW_PERMIT:
        handle_new_permit(buf, buf_len);
        break;
      case CMD_NEW_PERMIT_RING:
        handle_new_permit_ring(buf, buf_len);
        break;
      case CMD_REFACTOR_RING:
        handle_refactor_ring(buf, buf_len);
        break;
      case CMD_TEST_PERMIT:
        handle_test_permit(buf, buf_len);
        break;
      case CMD_TEST_PERMIT_RING:
        handle_test_permit_ring(buf, buf_len);
        break;
      default:
        _send_response(RES_ERROR, NULL, 0);
        break;
    }
  }
  else
  {
    _send_response(RES_ERROR, NULL, 0);
  }
}
Exemple #7
0
static void
parse_username_password(struct vsf_session* p_sess)
{
  while (1)
  {
    vsf_cmdio_get_cmd_and_arg(p_sess, &p_sess->ftp_cmd_str,
                              &p_sess->ftp_arg_str, 1);
    if (tunable_ftp_enable)
    {
      if (str_equal_text(&p_sess->ftp_cmd_str, "USER"))
      {
        handle_user_command(p_sess);
      }
      else if (str_equal_text(&p_sess->ftp_cmd_str, "PASS"))
      {
        handle_pass_command(p_sess);
      }
      else if (str_equal_text(&p_sess->ftp_cmd_str, "QUIT"))
      {
        vsf_cmdio_write_exit(p_sess, FTP_GOODBYE, "Goodbye.");
      }
      else if (str_equal_text(&p_sess->ftp_cmd_str, "FEAT"))
      {
        handle_feat(p_sess);
      }
      else if (str_equal_text(&p_sess->ftp_cmd_str, "OPTS"))
      {
        handle_opts(p_sess);
      }
      else if (tunable_ssl_enable &&
               str_equal_text(&p_sess->ftp_cmd_str, "AUTH") &&
               !p_sess->control_use_ssl)
      {
        handle_auth(p_sess);
      }
      else if (tunable_ssl_enable &&
               str_equal_text(&p_sess->ftp_cmd_str, "PBSZ"))
      {
        handle_pbsz(p_sess);
      }
      else if (tunable_ssl_enable &&
               str_equal_text(&p_sess->ftp_cmd_str, "PROT"))
      {
        handle_prot(p_sess);
      }
      else if (str_isempty(&p_sess->ftp_cmd_str) &&
               str_isempty(&p_sess->ftp_arg_str))
      {
        /* Deliberately ignore to avoid NAT device bugs, as per ProFTPd. */
      }
      else
      {
        vsf_cmdio_write(p_sess, FTP_LOGINERR,
                        "Please login with USER and PASS.");
      }
    }
    else if (tunable_http_enable)
    {
      if (str_equal_text(&p_sess->ftp_cmd_str, "GET"))
      {
        handle_get(p_sess);
      }
      else
      {
        vsf_cmdio_write(p_sess, FTP_LOGINERR, "Bad HTTP verb.");
      }
      vsf_sysutil_exit(0);
    }
  }
}
void
ltspfs_dispatch (int sockfd, XDR *in)
{
  int packet_type;

  if (!xdr_int(in, &packet_type)) {
    if (debug)
      info("Packet type decode failed!\n");
    close(sockfd);
    exit(1);
  }

  if (debug)
    info("Packet type: %s\n", ltspfs_opcode_str[packet_type]);

  if (!authenticated) {			/* Haven't authenticated yet */
    switch(packet_type) {
      case LTSPFS_XAUTH:
        handle_auth(sockfd, in);
	break;
      default:
        status_return(sockfd, FAIL);
    }
  } else if (!mountpoint) {
    switch(packet_type) {
      case LTSPFS_MOUNT:
        handle_mount(sockfd, in);	/* Haven't mounted yet */
	break;
      default:
        status_return(sockfd, FAIL);
    }
  } else if (packet_type == LTSPFS_PING) {
    ltspfs_ping(sockfd);
  } else {
    if (!mounted)
      am_mount(mountpoint);		/* this will return */

    switch(packet_type) {
      case LTSPFS_GETATTR:
        ltspfs_getattr(sockfd, in);
        break;
      case LTSPFS_READLINK:
        ltspfs_readlink(sockfd, in);
        break;
      case LTSPFS_READDIR:
        ltspfs_readdir(sockfd, in);
        break;
      case LTSPFS_MKNOD:
        ltspfs_mknod(sockfd, in);
        break;
      case LTSPFS_MKDIR:
        ltspfs_mkdir(sockfd, in);
        break;
      case LTSPFS_SYMLINK:
        ltspfs_symlink(sockfd, in);
        break;
      case LTSPFS_UNLINK:
        ltspfs_unlink(sockfd, in);
        break;
      case LTSPFS_RMDIR:
        ltspfs_rmdir(sockfd, in);
        break;
      case LTSPFS_RENAME:
        ltspfs_rename(sockfd, in);
        break;
      case LTSPFS_LINK:
        ltspfs_link(sockfd, in);
        break;
      case LTSPFS_CHMOD:
        ltspfs_chmod(sockfd, in);
        break;
      case LTSPFS_CHOWN:
        ltspfs_chown(sockfd, in);
        break;
      case LTSPFS_TRUNCATE:
        ltspfs_truncate(sockfd, in);
        break;
      case LTSPFS_UTIME:
        ltspfs_utime(sockfd, in);
        break;
      case LTSPFS_OPEN:
        ltspfs_open(sockfd, in);
        break;
      case LTSPFS_READ:
        ltspfs_read(sockfd, in);
        break;
      case LTSPFS_WRITE:
        ltspfs_write(sockfd, in);
        break;
      case LTSPFS_STATFS:
        ltspfs_statfs(sockfd, in);
        break;
      case LTSPFS_RELEASE:
      case LTSPFS_RSYNC:
      case LTSPFS_SETXATTR:
      case LTSPFS_GETXATTR:
      case LTSPFS_LISTXATTR:
      case LTSPFS_REMOVEXATTR:
        break;
      case LTSPFS_QUIT:
        ltspfs_quit(sockfd);
        break;
      default:
        status_return(sockfd, FAIL);
        if (debug)
          info("Invalid command: %d\n", packet_type);
    }
  }
}
Exemple #9
0
/**
 * mega_filesystem_load:
 * @filesystem: a #MegaFilesystem
 * @error: Error.
 *
 * Load data into the filesystem from the session.
 *
 * Returns: TRUE on success.
 */
gboolean mega_filesystem_load(MegaFilesystem* filesystem, GError** error)
{
  MegaFilesystemPrivate* priv;
  MegaAesKey* master_key;
  GError* local_err = NULL;
  gchar* f_node;
  GList* list = NULL;
  MegaSession* session = NULL;

  g_return_val_if_fail(MEGA_IS_FILESYSTEM(filesystem), FALSE);
  g_return_val_if_fail(error == NULL || *error == NULL, FALSE);

  priv = filesystem->priv;
  session = mega_filesystem_get_session(filesystem);
  master_key = mega_session_get_master_key(session);

  if (!session || !master_key)
  {
    g_clear_object(&session);
    return FALSE;
  }

  f_node = mega_api_call_simple(mega_session_get_api(session), 'o', &local_err, "{a:f, c:1}");
  if (!f_node)
  {
    g_propagate_error(error, local_err);
    g_clear_object(&session);
    return FALSE;
  }

  // process 'ok' array

  const gchar* ok_array = s_json_path(f_node, ".ok!a");
  if (ok_array)
  {
    S_JSON_FOREACH_ELEMENT(ok_array, ok)
      if (s_json_get_type(ok) != S_JSON_TYPE_OBJECT)
        continue;

      gchar* h = s_json_get_member_string(ok, "h");    // h.8 
      gchar* ha = s_json_get_member_string(ok, "ha");  // b64(aes(h.8 h.8, master_key))
      gchar* k = s_json_get_member_string(ok, "k");    // b64(aes(share_key_for_h, master_key))

      if (h && ha && k)
      {
        if (handle_auth(h, ha, master_key))
        {
          MegaAesKey* key = mega_aes_key_new_from_enc_ubase64(k, master_key);
          mega_filesystem_add_share_key(filesystem, h, key);
          g_object_unref(key);
        }
        else
          g_printerr("WARNING: Skipping import of a key %s because its authentication failed\n", h);
      }
      else
        g_printerr("WARNING: Skipping import of a key %s because it is missing required attributes\n", h);

      g_free(h);
      g_free(ha);
      g_free(k);
    S_JSON_FOREACH_END()
  }

  // process 'f' array

  const gchar* f_array = s_json_path(f_node, ".f!a");
  if (f_array)
  {
    S_JSON_FOREACH_ELEMENT(f_array, f)
      if (s_json_get_type(f) != S_JSON_TYPE_OBJECT)
        continue;

      MegaNode* node = mega_node_new(filesystem);
      if (mega_node_load(node, f, &local_err))
        list = g_list_prepend(list, node);
      else
      {
        g_printerr("WARNING: Skipping import of node: %s\n", local_err ? local_err->message : "unknown reason");
        g_clear_error(&local_err);
        g_object_unref(node);
      }
    S_JSON_FOREACH_END()
  }

  // import special root node for contacts
  list = g_list_prepend(list, mega_node_new_contacts(filesystem));

  // process 'u' array

  const gchar* u_array = s_json_path(f_node, ".u!a");
  if (u_array)
  {
    S_JSON_FOREACH_ELEMENT(u_array, u)
      if (s_json_get_type(u) != S_JSON_TYPE_OBJECT)
        continue;

      // skip self and removed
      gint64 c = s_json_get_member_int(u, "c", 0);
      if (c != 1)
        continue;

      MegaNode* node = mega_node_new(filesystem);
      if (mega_node_load_user(node, u, &local_err))
        list = g_list_prepend(list, node);
      else
      {
        g_printerr("WARNING: Skipping import of node: %s\n", local_err ? local_err->message : "unknown reason");
        g_clear_error(&local_err);
        g_object_unref(node);
      }
    S_JSON_FOREACH_END()
  }

  g_free(f_node);

  g_list_free_full(priv->nodes, (GDestroyNotify)g_object_unref);
  priv->nodes = g_list_reverse(list);

  update_maps(filesystem);

  priv->last_refresh = time(NULL);

  g_clear_object(&session);
  return TRUE;
}
Exemple #10
0
int main(int argc, char *argv[]) {
    int port = DEFAULTPORT;

    /* Handle command line options. */
    int next_opt = 0;
    const char *short_opts = "hp:";
    const struct option long_opts[] = {
        { "help",   0, NULL, 'h' },
        { "port",   1, NULL, 'p' },
        { NULL,     0, NULL, 0   }
    };

    while (next_opt != -1) {
        next_opt = getopt_long(argc, argv, short_opts, long_opts, NULL);
        switch (next_opt) {
            case 'h':
                usage(stdout, 0);
                break;

            case 'p':
                if ((port = valid_port(optarg)) < 0) {
                    fprintf(stderr, "Port must range from %d - %d\n\n", MINPORT, MAXPORT);
                    usage(stderr, 1);
                }
                break;

            case '?':
                usage(stderr, 1);
                break;

            case -1:
                break;

            default:
                fprintf(stderr, "Fatal error, aborting...\n");
                exit(1);
        }
    }

    /* There shouldn't be any other parameters. */
    if (argv[optind]) {
        fprintf(stderr, "Invalid parameter `%s'\n\n", argv[optind]);
        usage(stderr, 1);
    }

    /* Install the signal handlers to cleanup after children and at exit. */
    signal(SIGCHLD, (void (*)())cleanup);
    signal(SIGINT, (void(*)())wrapup);

    /* Create and configure the ssh session. */
    session=ssh_new();
    sshbind=ssh_bind_new();
    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDADDR, LISTENADDRESS);
    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "ssh-rsa");
    ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY,RSA_KEYFILE);

    /* Listen on `port' for connections. */
    if (ssh_bind_listen(sshbind) < 0) {
        printf("Error listening to socket: %s\n",ssh_get_error(sshbind));
        return -1;
    }
    if (DEBUG) { printf("Listening on port %d.\n", port); }

    /* Loop forever, waiting for and handling connection attempts. */
    while (1) {
        if (ssh_bind_accept(sshbind, session) == SSH_ERROR) {
            fprintf(stderr, "Error accepting a connection: `%s'.\n",ssh_get_error(sshbind));
            return -1;
        }
        if (DEBUG) { printf("Accepted a connection.\n"); }

        switch (fork())  {
            case -1:
                fprintf(stderr,"Fork returned error: `%d'.\n",-1);
                exit(-1);

            case 0:
                exit(handle_auth(session));

            default:
                break;
        }
    }

    return 0;
}
Exemple #11
0
static bool handle_line (s4pp_ctx_t *ctx, char *line, uint16_t len)
{
  if (line[len -1] == '\n')
    line[len -1] = 0;
  else
    goto protocol_error;
  if (strncmp ("S4PP/", line, 5) == 0)
  {
    // S4PP/x.y <algo,algo...> <max_samples>
    if (ctx->state != S4PP_CONNECT || !handle_hello (ctx, line))
      goto protocol_error;
  }
  else if (strncmp ("TOK:", line, 4) == 0)
  {
    if (ctx->state == S4PP_HELLO)
      handle_auth (ctx, line + 4, len - 5); // len - 5 => ditch \0
    else
      goto protocol_error;
  }
  else if (strncmp ("REJ:", line, 4) == 0)
    goto protocol_error;
  else if (strncmp ("NOK:", line, 4) == 0)
  {
    if (ctx->state != S4PP_COMMITTING)
      goto protocol_error;
    // we don't pipeline sequences, so don't need to check the seqno
    ctx->state = S4PP_AUTHED;
    invoke_done (ctx, false);
  }
  else if (strncmp ("OK:", line, 3) == 0)
  {
    if (ctx->state != S4PP_COMMITTING)
      goto protocol_error;
    ctx->proto_errs = 0;
    ctx->state = S4PP_AUTHED;
    invoke_done (ctx, true);
  }
  else if (strncmp ("NTFY:", line, 5) == 0)
  {
    char *argsp = 0;
    unsigned long code = strtoul (line + 5, &argsp, 10);
    unsigned nargs = 0;
    for (char *p = argsp; *p; ++p)
      if (*p == ',')
        ++nargs;
    const char **args = malloc (sizeof (char *) * (nargs + 1));
    if (args)
    {
      unsigned i = 0;
      for (char *p = argsp; *p; ++p)
      {
        if (*p == ',')
        {
          args[i++] = p + 1;
          *p = 0;
        }
      }
      args[i] = 0; // Be nice and leave a null at the end of args array
      ctx->ntfy (ctx, (unsigned)code, nargs, args);
      free (args);
    }
    // else silently ignore it? or whinge somehow? TODO
  }
  else
    goto protocol_error;
  return_res;

protocol_error:
  if (ctx->conn)
	ctx->io->disconnect (ctx->conn);
  ctx->conn = NULL;
  ctx->err = S4PP_PROTOCOL_ERROR;
  ctx->state = S4PP_ERRORED;
  if (ctx->proto_errs >= MAX_PROTOCOL_ERRORS_BEFORE_FATAL)
    ctx->fatal = true; // "escape hatch" to avoid reconnect hammering
  else
    ++ctx->proto_errs;
  invoke_done (ctx, false);
  return_res;
}
Exemple #12
0
/**
 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
 * @hapd: hostapd BSS data structure (the BSS to which the management frame was
 * sent to)
 * @buf: management frame data (starting from IEEE 802.11 header)
 * @len: length of frame data in octets
 * @fi: meta data about received frame (signal level, etc.)
 *
 * Process all incoming IEEE 802.11 management frames. This will be called for
 * each frame received from the kernel driver through wlan#ap interface. In
 * addition, it can be called to re-inserted pending frames (e.g., when using
 * external RADIUS server as an MAC ACL).
 */
void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
		     struct hostapd_frame_info *fi)
{
	struct ieee80211_mgmt *mgmt;
	int broadcast;
	u16 fc, stype;

	mgmt = (struct ieee80211_mgmt *) buf;
	fc = le_to_host16(mgmt->frame_control);
	stype = WLAN_FC_GET_STYPE(fc);

	if (stype == WLAN_FC_STYPE_BEACON) {
		handle_beacon(hapd, mgmt, len, fi);
		return;
	}

	broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
		mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
		mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;

	if (!broadcast &&
	    os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
		printf("MGMT: BSSID=" MACSTR " not our address\n",
		       MAC2STR(mgmt->bssid));
		return;
	}


	if (stype == WLAN_FC_STYPE_PROBE_REQ) {
		handle_probe_req(hapd, mgmt, len);
		return;
	}

	if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
		hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
			       HOSTAPD_LEVEL_DEBUG,
			       "MGMT: DA=" MACSTR " not our address",
			       MAC2STR(mgmt->da));
		return;
	}

	switch (stype) {
	case WLAN_FC_STYPE_AUTH:
		wpa_printf(MSG_DEBUG, "mgmt::auth");
		handle_auth(hapd, mgmt, len);
		break;
	case WLAN_FC_STYPE_ASSOC_REQ:
		wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
		handle_assoc(hapd, mgmt, len, 0);
		break;
	case WLAN_FC_STYPE_REASSOC_REQ:
		wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
		handle_assoc(hapd, mgmt, len, 1);
		break;
	case WLAN_FC_STYPE_DISASSOC:
		wpa_printf(MSG_DEBUG, "mgmt::disassoc");
		handle_disassoc(hapd, mgmt, len);
		break;
	case WLAN_FC_STYPE_DEAUTH:
		wpa_printf(MSG_DEBUG, "mgmt::deauth");
		handle_deauth(hapd, mgmt, len);
		break;
	case WLAN_FC_STYPE_ACTION:
		wpa_printf(MSG_DEBUG, "mgmt::action");
		handle_action(hapd, mgmt, len);
		break;
	default:
		hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
			       HOSTAPD_LEVEL_DEBUG,
			       "unknown mgmt frame subtype %d", stype);
		break;
	}
}