예제 #1
0
/* Given the tagged parameter sets from a beacon packet, locate the AP's SSID and return its current channel number */
int parse_beacon_tags(const u_char *packet, size_t len)
{
    char *ssid = NULL;
    const u_char *tag_data = NULL;
    unsigned char *ie = NULL, *channel_data = NULL;
    size_t ie_len = 0, ie_offset = 0, tag_len = 0, tag_offset = 0;
    int channel = 0;
    struct radio_tap_header *rt_header = NULL;

    rt_header = (struct radio_tap_header *) radio_header(packet, len);
    tag_offset = rt_header->len + sizeof(struct dot11_frame_header) + sizeof(struct beacon_management_frame);

    if(tag_offset < len)
    {
        tag_len = (len - tag_offset);
        tag_data = (const u_char *) (packet + tag_offset);

        /* If no SSID was manually specified, parse and save the AP SSID */
        if(get_ssid() == NULL)
        {
            ie = parse_ie_data(tag_data, tag_len, (uint8_t) SSID_TAG_NUMBER, &ie_len, &ie_offset);
            if(ie)
            {
                /* Return data is not null terminated; allocate ie_len+1 and memcpy string */
                ssid = malloc(ie_len+1);
                if(ssid)
                {
                    memset(ssid, 0, (ie_len+1));
                    memcpy(ssid, ie, ie_len);
                    set_ssid(ssid);
                    free(ssid);
                }

                free(ie);
            }
        }

        ie = parse_ie_data(tag_data, tag_len, (uint8_t) RATES_TAG_NUMBER, &ie_len, &ie_offset);
        if(ie)
        {
            set_ap_rates(ie, ie_len);
            free(ie);
        }

        channel_data = parse_ie_data(tag_data, tag_len, (uint8_t) CHANNEL_TAG_NUMBER, &ie_len, &ie_offset);
        if(channel_data)
        {
            if(ie_len  == 1)
            {
                memcpy((int *) &channel, channel_data, ie_len);
            }
            free(channel_data);
        }
    }

    return channel;
}
예제 #2
0
/* Process auto-applied options from the database. read_ap_beacon should be called before this. */
void process_auto_options(void)
{
	char **argv = NULL;
	int argc = 0, i = 0;
	char *bssid = NULL, *ssid = NULL;

	if(get_auto_detect_options())
	{
		bssid = (char *) mac2str(get_bssid(), ':');


		if(bssid)
		{
			/* If we didn't get the SSID from the beacon packet, check the database */
			if(get_ssid() == NULL)
			{
				ssid = get_db_ssid(bssid);
				if(ssid)
				{
					set_ssid(ssid);
					free(ssid);
				}
			}

			argv = auto_detect_settings(bssid, &argc);
			if(argc > 1 && argv != NULL)
			{
				/* Process the command line arguments */
				process_arguments(argc, argv);

				/* Clean up argument memory allocation */
				for(i=0; i<argc; i++)
				{
					free(argv[i]);
				}
				free(argv);
			}

			free(bssid);
		}
	}

	return;
}
예제 #3
0
int
save_service_list (const service_list *sl)
{
  struct gen_ssid_arg arg = {
    .ssid = "##",
    .ssid_len = 2,
    .last_pos = -1,
    .rc = ERR_SUCCESS,
  };
  char *err_msg;
  int rc;
  char old_ssid[SSID_MAX_LEN];
  ssize_t old_ssid_len;
  sqlite3_stmt *updt_stmt;

  if (!sl->has_service_list_tmp_table)
    {
      return ERR_SUCCESS;
    }

  /* Constructing the SSID */
  if ((rc = sqlite3_exec (sl->db,
			  "select "
			  COLUMN_CAT_ID ", " COLUMN_DESC ", " COLUMN_POSITION
			  " from " TABLE_SERVICE_LIST_TMP
			  " order by " COLUMN_POSITION " asc",
			  gen_ssid, &arg, &err_msg)) != SQLITE_ABORT
      && rc != SQLITE_OK)
    {
      SQLITE3_ERR_STR (err_msg, "Cannot select services to publish");
      return ERR_SAVE_SERVICE_LIST;
    }
  if (rc == SQLITE_ABORT)
    {
      sqlite3_free (err_msg);
      l->APP_ERR (arg.rc, "Cannot publish services");
      return arg.rc;
    }

  /* Preparing for reverting to the old SSID */
  if ((old_ssid_len = get_ssid (old_ssid, sizeof (old_ssid))) == -1)
    {
      l->ERR ("Cannot retrieve old SSID");
      return ERR_SAVE_SERVICE_LIST;
    }

  /* Give modification time to all records in the temporary table */
  if (sqlite3_exec (sl->db,
		    "update " TABLE_SERVICE_LIST_TMP
		    " set " COLUMN_MOD_TIME " = strftime ('%s', 'now')",
		    NULL, NULL, &err_msg))
    {
      SQLITE3_ERR_STR (err_msg, "Cannot set service list new mod time");
      return ERR_SAVE_SERVICE_LIST;
    }
  
  /* If there old and new records are the same, don't change the mod time */
  if (sqlite3_prepare_v2 (sl->db,
			  "update " TABLE_SERVICE_LIST_TMP " set "
			  COLUMN_MOD_TIME " = ?"
			  " where " COLUMN_POSITION " = ?"
			  " and " COLUMN_CAT_ID " = ?"
			  " and " COLUMN_DESC " = ?"
			  " and " COLUMN_LONG_DESC " = ?"
			  " and " COLUMN_URI " = ?",
			  -1,
			  &updt_stmt,
			  NULL))
    {
      SQLITE3_ERR (sl->db, "Cannot prepare mod time adjustment update statement");
      return ERR_SAVE_SERVICE_LIST;
    }
  if ((rc = sqlite3_exec (sl->db, "select * from " TABLE_SERVICE_LIST,
			  adjust_mod_time, updt_stmt, &err_msg)))
    {
      SQLITE3_ERR_STR (err_msg, "Cannot adjust mod time");
    }
  if (sqlite3_finalize (updt_stmt))
    {
      SQLITE3_ERR_STR (err_msg, "Cannot finalize mod time adjustment stmt");
      return ERR_SAVE_SERVICE_LIST;
    }
  if (rc)
    {
      return ERR_SAVE_SERVICE_LIST;
    }

  /* The real saving process */
  if (sqlite3_exec (sl->db, "begin exclusive", NULL, NULL, &err_msg))
    {
      SQLITE3_ERR_STR (err_msg, "Cannot lock service list DB");
      return ERR_SAVE_SERVICE_LIST;
    }
  if ((rc = set_ssid (arg.ssid, arg.ssid_len)))
    {
      l->APP_ERR (rc, "Cannot set SSID");
      if (sqlite3_exec (sl->db, "rollback", NULL, NULL, &err_msg))
	{
	  SQLITE3_ERR_STR (err_msg,
			      "Cannot unlock (rollback) service list DB");
	}
      return rc;
    }
  if (sqlite3_exec (sl->db,
		    "delete from " TABLE_SERVICE_LIST ";"
		    "insert into " TABLE_SERVICE_LIST
		    " select *"
		    " from " TABLE_SERVICE_LIST_TMP ";"
		    "commit",
		    NULL, NULL, &err_msg))
    {
      SQLITE3_ERR_STR (err_msg, "Cannot save services");
      if ((rc = set_ssid (old_ssid, old_ssid_len)))
	{
	  l->APP_ERR (rc, "Cannot revert back to the old SSID");
	}
      if (sqlite3_exec (sl->db, "rollback", NULL, NULL, &err_msg))
	{
	  SQLITE3_ERR_STR (err_msg,
			      "Cannot unlock (rollback) service list DB");
	}
      return ERR_SAVE_SERVICE_LIST;
    }
  
  return ERR_SUCCESS;
}

/**
 * The callback function used with sqlite3_exec() to count the rows
 * of a table. The SQL select in sqlite3_exec() <strong>MUST</strong>
 * correct in returning only one row having only one column containing
 * the count to be extracted.
 *
 * @param [out] result where the counting result should be put.
 * @param [in] col_count the number of columns in this record.
 * @param [in] cols the columns of this record.
 * @param [in] col_names the column names of this record.
 *
 * @return 0 if there is no error or non-zero if there is one.
 */
static int
get_row_count (void *result, int col_count, char **cols, char **col_names)
{
  unsigned long *count = result;

  *count = strtoul (cols[0], NULL, 10);

  return 0;
}
예제 #4
0
void
publish_services (void)
{
  struct gen_ssid_arg arg = {
    .ssid = "##",
    .ssid_len = 2,
    .last_pos = -1,
    .rc = ERR_SUCCESS,
  };
  char *err_msg;
  int rc;
  sqlite3 *db;

  if (sqlite3_open_v2 (SERVICE_LIST_DB, &db, SQLITE_OPEN_READONLY, NULL))
    {
      SQLITE3_ERR (db,
		   "Cannot open DB in read-only mode for publishing services");
      goto error;
    }

  if ((rc = sqlite3_exec (db,
			  "select "
			  COLUMN_CAT_ID ", " COLUMN_DESC ", " COLUMN_POSITION
			  " from " TABLE_SERVICE_LIST
			  " order by " COLUMN_POSITION " asc",
			  gen_ssid, &arg, &err_msg)) != SQLITE_ABORT
      && rc != SQLITE_OK)
    {
      SQLITE3_ERR_STR (err_msg, "Cannot select services to publish");
      goto error;
    }
  if (rc == SQLITE_ABORT)
    {
      sqlite3_free (err_msg);
      l->APP_ERR (arg.rc, "Cannot publish services");
      goto error;
    }

  if ((rc = set_ssid (arg.ssid, arg.ssid_len)))
    {
      l->APP_ERR (rc, "Cannot set SSID");
    }

 error:
  if (sqlite3_close (db))
    {
      SQLITE3_ERR (db,
		   "Cannot close read-only DB for reading published services");
    }
}

/**
 * The callback function used with sqlite3_exec() to not change the modification
 * time of unmodified record. The SQL select in sqlite3_exec()
 * <strong>MUST</strong> select all columns with '*'.
 *
 * @param [in] stmt the prepared statement to adjust the modification time.
 * @param [in] col_count the number of columns in this record.
 * @param [in] cols the columns of this record.
 * @param [in] col_names the column names of this record.
 *
 * @return 0 if there is no error or non-zero if there is one.
 */
static int
adjust_mod_time (void *stmt, int col_count, char **cols, char **col_names)
{
  sqlite3_stmt *updt_stmt = stmt;
  sqlite3 *db = sqlite3_db_handle (updt_stmt);

  if (sqlite3_bind_text (stmt, 1, cols[COLPOS_MOD_TIME], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind mod_time to updt stmt");
      return -1;
    }
  if (sqlite3_bind_text (stmt, 2, cols[COLPOS_POSITION], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind position to updt stmt");
      return -1;
    }
  if (sqlite3_bind_text (stmt, 3, cols[COLPOS_CAT_ID], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind cat_id to updt stmt");
      return -1;
    }
  if (sqlite3_bind_text (stmt, 4, cols[COLPOS_DESC], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind desc to updt stmt");
      return -1;
    }
  if (sqlite3_bind_text (stmt, 5, cols[COLPOS_LONG_DESC], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind long_desc to updt stmt");
      return -1;
    }
  if (sqlite3_bind_text (stmt, 6, cols[COLPOS_URI], -1, SQLITE_STATIC))
    {
      SQLITE3_ERR (db, "Cannot bind uri to updt stmt");
      return -1;
    }

  if (sqlite3_step (stmt) != SQLITE_DONE)
    {
      SQLITE3_ERR (db, "Cannot execute updt stmt");
      return -1;
    }

  if (sqlite3_reset (stmt))
    {
      SQLITE3_ERR (db, "Cannot reset updt stmt");
      return -1;
    }
  if (sqlite3_clear_bindings (stmt))
    {
      SQLITE3_ERR (db, "Cannot clear updt stmt bindings");
      return -1;
    }

  return 0;
}
예제 #5
0
파일: wpsmon.c 프로젝트: siro20/reaver-wps
void parse_wps_settings(const u_char *packet, struct pcap_pkthdr *header, char *target, int passive, int mode, int source)
{
	struct radio_tap_header *rt_header = NULL;
	struct dot11_frame_header *frame_header = NULL;
	struct libwps_data *wps = NULL;
	enum encryption_type encryption = NONE;
	char *bssid = NULL, *ssid = NULL, *lock_display = NULL;
	int wps_parsed = 0, probe_sent = 0, channel = 0, rssi = 0;
	static int channel_changed = 0;

	wps = malloc(sizeof(struct libwps_data));
	memset(wps, 0, sizeof(struct libwps_data));

	if(packet == NULL || header == NULL || header->len < MIN_BEACON_SIZE)
        {
                goto end;
        }

	rt_header = (struct radio_tap_header *) radio_header(packet, header->len);
	frame_header = (struct dot11_frame_header *) (packet + rt_header->len);

	/* If a specific BSSID was specified, only parse packets from that BSSID */
	if(!is_target(frame_header))
	{
		goto end;
	}

	set_ssid(NULL);
	bssid = (char *) mac2str(frame_header->addr3, ':');

	if(bssid)
	{
		if((target == NULL) ||
		   (target != NULL && strcmp(bssid, target) == 0))
		{
			channel = parse_beacon_tags(packet, header->len);
			rssi = signal_strength(packet, header->len);
			ssid = (char *) get_ssid();

			if(target != NULL && channel_changed == 0)
			{
				ualarm(0, 0);
				change_channel(channel);
				channel_changed = 1;
			}

			if(frame_header->fc.sub_type == PROBE_RESPONSE ||
                                   frame_header->fc.sub_type == SUBTYPE_BEACON)
			{
				wps_parsed = parse_wps_parameters(packet, header->len, wps);
			}
	
			if(!is_done(bssid) && (get_channel() == channel || source == PCAP_FILE || !get_channel()))
			{
				if(frame_header->fc.sub_type == SUBTYPE_BEACON && 
				   mode == SCAN && 
				   !passive && 
				   should_probe(bssid))
				{
					send_probe_request(get_bssid(), get_ssid());
					probe_sent = 1;
				}
		
				if(!insert(bssid, ssid, wps, encryption, rssi))
				{
					update(bssid, ssid, wps, encryption);
				}
				else if(wps->version > 0)
				{
					switch(wps->locked)
					{
						case WPSLOCKED:
							lock_display = YES;
							break;
						case UNLOCKED:
						case UNSPECIFIED:
							lock_display = NO;
							break;
					}

					cprintf(INFO, "%17s      %2d            %.2d        %d.%d               %s               %s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid);
				}

				if(probe_sent)
				{
					update_probe_count(bssid);
				}

				/* 
				 * If there was no WPS information, then the AP does not support WPS and we should ignore it from here on.
				 * If this was a probe response, then we've gotten all WPS info we can get from this AP and should ignore it from here on.
				 */
				if(!wps_parsed || frame_header->fc.sub_type == PROBE_RESPONSE)
				{
					mark_ap_complete(bssid);
				}
	
			}
		}

		/* Only update received signal strength if we are on the same channel as the AP, otherwise power measurements are screwy */
		if(channel == get_channel())
		{
			update_ap_power(bssid, rssi);
		}

		free(bssid);
		bssid = NULL;
	}
예제 #6
0
void parse_wps_settings(const u_char *packet, struct pcap_pkthdr *header, char *target, int passive, int mode, int source)
{
    struct radio_tap_header *rt_header = NULL;
    struct dot11_frame_header *frame_header = NULL;
    struct libwps_data *wps = NULL;
    enum encryption_type encryption = NONE;
    char *bssid = NULL, *ssid = NULL, *lock_display = NULL;
    int wps_parsed = 0, probe_sent = 0, channel = 0, rssi = 0;
    static int channel_changed = 0;
    
    char info_manufac[500];
    char info_modelnum[500];
    char info_modelserial[500];

    wps = malloc(sizeof(struct libwps_data));
    memset(wps, 0, sizeof(struct libwps_data));

    if(packet == NULL || header == NULL || header->len < MIN_BEACON_SIZE)
    {
        goto end;
    }

    rt_header = (struct radio_tap_header *) radio_header(packet, header->len);
    frame_header = (struct dot11_frame_header *) (packet + rt_header->len);

    /* If a specific BSSID was specified, only parse packets from that BSSID */
    if(!is_target(frame_header))
    {
        goto end;
    }

    set_ssid(NULL);
    bssid = (char *) mac2str(frame_header->addr3, ':');
    set_bssid((unsigned char *) frame_header->addr3);

    if(bssid)
    {
        if((target == NULL) ||
                (target != NULL && strcmp(bssid, target) == 0))
        {
            channel = parse_beacon_tags(packet, header->len);
            rssi = signal_strength(packet, header->len);
            ssid = (char *) get_ssid();

            if(target != NULL && channel_changed == 0)
            {
                ualarm(0, 0);
                change_channel(channel);
                channel_changed = 1;
            }

            if(frame_header->fc.sub_type == PROBE_RESPONSE ||
                    frame_header->fc.sub_type == SUBTYPE_BEACON)
            {
                wps_parsed = parse_wps_parameters(packet, header->len, wps);
            }

            if(!is_done(bssid) && (get_channel() == channel || source == PCAP_FILE))
            {
                if(frame_header->fc.sub_type == SUBTYPE_BEACON && 
                        mode == SCAN && 
                        !passive && 
                        should_probe(bssid))
                {
                    send_probe_request(get_bssid(), get_ssid());
                    probe_sent = 1;
                }

                if(!insert(bssid, ssid, wps, encryption, rssi))
                {
                    update(bssid, ssid, wps, encryption);
                }
                else if(wps->version > 0)
                {
                    switch(wps->locked)
                    {
                        case WPSLOCKED:
                            lock_display = YES;
                            break;
                        case UNLOCKED:
                        case UNSPECIFIED:
                            lock_display = NO;
                            break;
                    }
					
					//ideas made by kcdtv
					
					if(get_chipset_output == 1)
					//if(1)
					{
						if (c_fix == 0)
						{
							//no use a fixed channel
							cprintf(INFO,"Option (-g) REQUIRES a channel to be set with (-c)\n");
							exit(0);
						}
						
						FILE *fgchipset=NULL;
						char cmd_chipset[4000];
						char cmd_chipset_buf[4000];
						char buffint[5];
						
						char *aux_cmd_chipset=NULL;
						

						
						memset(cmd_chipset, 0, sizeof(cmd_chipset));
						memset(cmd_chipset_buf, 0, sizeof(cmd_chipset_buf));
						memset(info_manufac, 0, sizeof(info_manufac));
                        memset(info_modelnum, 0, sizeof(info_modelnum));
                        memset(info_modelserial, 0, sizeof(info_modelserial));
						

						
						strcat(cmd_chipset,"reaver -0 -s y -vv -i "); //need option to stop reaver in m1 stage
						strcat(cmd_chipset,get_iface());
						
						strcat(cmd_chipset, " -b ");
						strcat(cmd_chipset, mac2str(get_bssid(),':'));
						
						strcat(cmd_chipset," -c ");
						snprintf(buffint, sizeof(buffint), "%d",channel);
						strcat(cmd_chipset, buffint);
						
						//cprintf(INFO,"\n%s\n",cmd_chipset);

						if ((fgchipset = popen(cmd_chipset, "r")) == NULL) {
							printf("Error opening pipe!\n");
							//return -1;
						}
						
						

						while (fgets(cmd_chipset_buf, 4000, fgchipset) != NULL) 
						{
							//[P] WPS Manufacturer: xxx
							//[P] WPS Model Number: yyy
							//[P] WPS Model Serial Number: zzz
							//cprintf(INFO,"\n%s\n",cmd_chipset_buf);

							aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Manufacturer:");
							if(aux_cmd_chipset != NULL)
							{
								//bug fix by alxchk
								strncpy(info_manufac, aux_cmd_chipset+21, sizeof(info_manufac));							
							}

							aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Model Number:");
							if(aux_cmd_chipset != NULL)
							{
                                //bug fix by alxchk
								strncpy(info_modelnum, aux_cmd_chipset+21, sizeof(info_modelnum));
								
							}

							aux_cmd_chipset = strstr(cmd_chipset_buf,"[P] WPS Model Serial Number:");
							if(aux_cmd_chipset != NULL)
							{
                                //bug fix by alxchk
								strncpy(info_modelserial, aux_cmd_chipset+28, sizeof(info_modelserial));
								
							}

						}
						
						//cprintf(INFO,"\n%s\n",info_manufac);
						info_manufac[strcspn ( info_manufac, "\n" )] = '\0';
						info_modelnum[strcspn ( info_modelnum, "\n" )] = '\0';
						info_modelserial[strcspn ( info_modelserial, "\n" )] = '\0';
						


                        if(pclose(fgchipset))  {
                        //printf("Command not found or exited with error status\n");
                        //return -1;
                        }

					

					}
					
					
					if (o_file_p == 0)
					{
						cprintf(INFO, "%17s      %2d            %.2d        %d.%d               %s               %s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid);
					}
					else
					{
						if(get_chipset_output == 1)
						{
							cprintf(INFO, "%17s|%2d|%.2d|%d.%d|%s|%s|%s|%s|%s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid, info_manufac, info_modelnum, info_modelserial);
							
						}else
						{
							cprintf(INFO, "%17s|%2d|%.2d|%d.%d|%s|%s\n", bssid, channel, rssi, (wps->version >> 4), (wps->version & 0x0F), lock_display, ssid);
							
						}
						
					}
예제 #7
0
/* Processes Reaver command line options */
int process_arguments(int argc, char **argv)
{
	int ret_val = EXIT_SUCCESS;
	int c = 0, channel = 0;
	int long_opt_index = 0;
	char bssid[MAC_ADDR_LEN] = { 0 };
	char mac[MAC_ADDR_LEN] = { 0 };
	char *short_options = "b:e:m:i:t:d:c:T:x:r:g:l:o:p:s:C:KZA5ELfnqvDShwN6J";
	struct option long_options[] = {
		{ "pixie-dust", no_argument, NULL, 'K' },
		{ "interface", required_argument, NULL, 'i' },
		{ "bssid", required_argument, NULL, 'b' },
		{ "essid", required_argument, NULL, 'e' },
		{ "mac", required_argument, NULL, 'm' },
		{ "timeout", required_argument, NULL, 't' },
		{ "m57-timeout", required_argument, NULL, 'T' },
		{ "delay", required_argument, NULL, 'd' },
		{ "lock-delay", required_argument, NULL, 'l' },
		{ "fail-wait", required_argument, NULL, 'x' },
		{ "channel", required_argument, NULL, 'c' },
		{ "session", required_argument, NULL, 's' },
		{ "recurring-delay", required_argument, NULL, 'r' },
		{ "max-attempts", required_argument, NULL, 'g' },
		{ "out-file", required_argument, NULL, 'o' },
		{ "pin", required_argument, NULL, 'p' },
		{ "exec", required_argument, NULL, 'C' },
		{ "no-associate", no_argument, NULL, 'A' },
		{ "ignore-locks", no_argument, NULL, 'L' },
		{ "no-nacks", no_argument, NULL, 'N' },
		{ "eap-terminate", no_argument, NULL, 'E' },
		{ "dh-small", no_argument, NULL, 'S' },
		{ "fixed", no_argument, NULL, 'f' },
		{ "daemonize", no_argument, NULL, 'D' },
		{ "5ghz", no_argument, NULL, '5' },
		{ "repeat-m6", no_argument, NULL, '6' },
		{ "nack", no_argument, NULL, 'n' },
		{ "quiet", no_argument, NULL, 'q' },
		{ "verbose", no_argument, NULL, 'v' },
		{ "win7", no_argument, NULL, 'w' },
		{ "help", no_argument, NULL, 'h' },
		{ "timeout-is-nack", no_argument, NULL, 'J' },
		{ 0, 0, 0, 0 }
	};

	/* Since this function may be called multiple times, be sure to set opt index to 0 each time */
	optind = 0;

	while((c = getopt_long(argc, argv, short_options, long_options, &long_opt_index)) != -1)
        {
                switch(c)
                {
                        case 'Z':
                        case 'K':
                                pixie.do_pixie = 1;
                                break;
                        case 'i':
                                set_iface(optarg);
                                break;
                        case 'b':
                                str2mac(optarg, (unsigned char *) &bssid);
                                set_bssid((unsigned char *) &bssid);
                                break;
                        case 'e':
                                set_ssid(optarg);
                                break;
                        case 'm':
                                str2mac(optarg, (unsigned char *) &mac);
                                set_mac((unsigned char *) &mac);
                                break;
                        case 't':
                                set_rx_timeout(atoi(optarg));
                                break;
                        case 'T':
                                set_m57_timeout(strtof(optarg, NULL) * SEC_TO_US);
                                break;
                        case 'c':
				channel = strtod(optarg, NULL);
                                set_fixed_channel(1);
                                break;
                        case '5':
                                set_wifi_band(AN_BAND);
                                break;
                        case '6':
                                set_repeat_m6(1);
                                break;
                        case 'd':
                                set_delay(atoi(optarg));
                                break;
                        case 'l':
                                set_lock_delay(atoi(optarg));
                                break;
			case 'p':
				parse_static_pin(optarg);
				break;
			case 's':       
				set_session(optarg);   
				break;
			case 'C':
				set_exec_string(optarg);
				break;
			case 'A':
				set_external_association(1);
				break;
                        case 'L':
                                set_ignore_locks(1);
                                break;
			case 'o':
				set_log_file(fopen(optarg, "w"));
				break;
                        case 'x':
                                set_fail_delay(atoi(optarg));
                                break;
                        case 'r':
                                parse_recurring_delay(optarg);
                                break;
                        case 'g':
                                set_max_pin_attempts(atoi(optarg));
                                break;
                        case 'D':
				daemonize();
				break;
			case 'E':
                                set_eap_terminate(1);
                                break;
			case 'S':
				set_dh_small(1);
				break;
                        case 'n':
				cprintf(INFO, "[+] ignoring obsolete -n switch\n");
				break;
			case 'J':
                                set_timeout_is_nack(1);
                                break;
                        case 'f':
                                set_fixed_channel(1);
                                break;
                        case 'v':
                                set_debug(get_debug() + 1);
                                break;
                        case 'q':
                                set_debug(CRITICAL);
                                break;
			case 'w':
				set_win7_compat(1);
				break;
			case 'N':
				set_oo_send_nack(0);
				break;
                        default:
                                ret_val = EXIT_FAILURE;
                }
        }

	if(channel)
	{
		change_channel(channel);
	}

	return ret_val;
}
예제 #8
0
파일: cuci.c 프로젝트: lonegoli/R7000
void _setConfigurations(cJSON *root, s_config *config, char *http_packet)
{
	cJSON *valueSetObj= cJSON_CreateObject();
	cJSON *attribute;
	cJSON *key;
	cJSON *item;
	int array_size;
	int i;
	char cmd[MAX_BUF];
	char result[MAX_BUF];
	char ErrMesg[B_5_BUF];
	cJSON *transaction_id = cJSON_GetObjectItem(root, "transaction_id");
	char *conf_version;
	char *radio_index;
	char *profile_index;
	char *status;
	int flag =0;
	if(!transaction_id) {
		debug(LOG_ERR, "Can not find transaction_id parameter: %s", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, NULL, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{transaction_id}", config->sn, http_packet);
		return;

	}
	cJSON *valueSet = cJSON_GetObjectItem(root, "valueSet");
	if(!valueSet) {
		debug(LOG_ERR, "Get valueSet faild[%s]", cJSON_GetErrorPtr());
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{valueSet}", config->sn, http_packet);
		return;
	}
	/*
	if((key = cJSON_GetObjectItem(valueSet, "conf_version")) == NULL || (conf_version = key->valuestring) == NULL) {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{conf_version}", config->sn, http_packet);
		return;
	}
	*/
	ErrMesg[0]=0;
	//setDeviceInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setDeviceInfo")) != NULL) {
			if((key = cJSON_GetObjectItem(attribute, "apname")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config apname %s\n", key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_apname(key->valuestring, result, sizeof(result)/sizeof(result[0]));
				}
		}
	}
	//setRadioInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setRadioInfo")) != NULL) {
			array_size = cJSON_GetArraySize(attribute);
			debug(LOG_DEBUG, "Array size of paras is %d",array_size);
 			for(i=0; i< array_size; i++) {
				item = cJSON_GetArrayItem(attribute, i);
				//debug(LOG_DEBUG, "%s\n",item->valuestring);
				if((key = cJSON_GetObjectItem(item, "radio_index")) == NULL || (radio_index = radio_keywords[parse_radio_keywords(key->valuestring)].value) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{radio_index}", config->sn, http_packet);
					return;
				}
				/*
				if((key = cJSON_GetObjectItem(item, "radio")) != NULL && key->valuestring != NULL) {
					snprintf(cmd, MAX_BUF, "config interface wlan %s radio %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					//debug(LOG_INFO, "result is %d", strlen(result));
				}
				*/
				if((key = cJSON_GetObjectItem(item, "mode")) != NULL && key->valuestring != NULL) {
					/*snprintf(cmd, MAX_BUF, "config interface wlan %s mode %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
			
					set_mode(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "power")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s power %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_power(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "channel")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channel %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_channel(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				if((key = cJSON_GetObjectItem(item, "channelwidth")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s channelwidth %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_channelwidth(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
	
				}
				if((key = cJSON_GetObjectItem(item, "max-wireless-clients")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s max-wireless-clients %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_max_assoc(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "client-isolation")) != NULL && key->valuestring != NULL) {
					/*
					snprintf(cmd, MAX_BUF, "config interface wlan %s client-isolation %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
					*/
					set_ap_isolate(atoi(radio_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
					
				}
				/*
				if((key = cJSON_GetObjectItem(item, "rate")) != NULL && key->valuestring != NULL) {
					snprintf(cmd, MAX_BUF, "config interface wlan %s rate %s\n", cJSON_GetObjectItem(item, "radio_index")->valuestring, key->valuestring);
					
					if(set_config(cmd, result)) 
						strcpy(ErrMesg, result);
				}	
				*/
 			}
		}
	}
	//setSSIDInfo//
	{
		if((attribute = cJSON_GetObjectItem(valueSet, "setSSIDInfo")) != NULL) {
			array_size = cJSON_GetArraySize(attribute);
			debug(LOG_DEBUG, "Array size of paras is %d",array_size);
 			for(i=0; i< array_size; i++) {
				item = cJSON_GetArrayItem(attribute, i);
				if((key = cJSON_GetObjectItem(item, "radio_index")) == NULL || (radio_index = radio_keywords[parse_radio_keywords(key->valuestring)].value) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{radio_index}", config->sn, http_packet);
					return;
				}
				if((key = cJSON_GetObjectItem(item, "profile_index")) == NULL || (profile_index = key->valuestring) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{profile_index}", config->sn, http_packet);
					return;
				}
				if((key = cJSON_GetObjectItem(item, "status")) == NULL || (status = key->valuestring) == NULL) {
					create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "3", "Missing parameter:{status}", config->sn, http_packet);
					return;
				}
				if(atoi(profile_index)>0) {
					char vifs[128];
					char viname[32];
					sprintf(viname, "wl%d.%d", atoi(radio_index), atoi(profile_index));
					read_vifs(atoi(radio_index), vifs, sizeof(vifs)/sizeof(vifs[0]));
	
					if(strstr(vifs, viname) && atoi(status)==0) {
						del_virtual_interface(atoi(radio_index), atoi(profile_index));
					}
					else if(!strstr(vifs, viname) && atoi(status)==1) {
						add_virtual_interface(atoi(radio_index), atoi(profile_index));
					}
					else if((!strstr(vifs, viname) && atoi(status)==0) || atoi(profile_index)>3) {
						continue;
					}
					
				}
				if((key = cJSON_GetObjectItem(item, "hide-network-name")) != NULL && key->valuestring != NULL) {
					set_status(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);	
				}
				if((key = cJSON_GetObjectItem(item, "ssid")) != NULL && key->valuestring != NULL) {
					set_ssid(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
						
				}
				if((key = cJSON_GetObjectItem(item, "authentication")) != NULL && key->valuestring != NULL) {
					
					set_security_mode(atoi(radio_index), atoi(profile_index), authentication_keywords[parse_authentication_keywords(key->valuestring)].value, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				
				if((key = cJSON_GetObjectItem(item, "encryption")) != NULL && key->valuestring != NULL) {
					set_crypto(atoi(radio_index), atoi(profile_index), encryption_keywords[parse_encryption_keywords(key->valuestring)].value, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}

				if((key = cJSON_GetObjectItem(item, "presharedkey")) != NULL && key->valuestring != NULL) {
					set_wpa_psk(atoi(radio_index), atoi(profile_index), key->valuestring, result, sizeof(result)/sizeof(result[0]));
					strcpy(ErrMesg, result);
				}
				flag =1;
 			}
			
		}
		
 	}
 	{
 		//apply_setting();
 		/*
 		int result;
		pthread_t tid_init_service = 0;
		config->upgrade_lock = 1;
 		debug(LOG_INFO, "create a new thread (thread_init_service)");
		result = pthread_create(&tid_init_service, NULL, (void *)thread_init_service, NULL);
		if (result != 0) {
			debug(LOG_ERR, "FATAL: Failed to create a new thread (init_service) - exiting");
			exit(1);
		}*/
		system("nvram commit");
		
 	}
 
	if(strlen(ErrMesg)) {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "failed", "1000", ErrMesg, config->sn, http_packet);
	}
	else {
		create_http_json(valueSetObj, transaction_id->valuestring, RESPONSE, SETCONFIGURATIONS, "success", "0", NULL, config->sn, http_packet);
	}
	if(flag) {
		safe_encrypt_http_send(config->httpfd, http_packet, strlen(http_packet), 0); 
		shutdown(config->httpfd, SHUT_RDWR);
		system("reboot");
	}
		
			
}
예제 #9
0
파일: mid_func_arch.c 프로젝트: jhbsz/cpe-1
int set_wlan_basic(int radio)
{
    int vap_enable;
    int radio_nvram_enable;
    int i;
    int vap_num;
    int wlan_mode = -1;
    nvram_get_radio_status(radio, &radio_nvram_enable);
    nvram_get_wlan_mode(radio, &wlan_mode);

    if(RADIO_DOWN == radio_nvram_enable)
        {
            //Kill all the security daemon first
//            if(WLAN_MODE_AP == wlan_mode)
//            {
                radio_up_down(radio, RADIO_DOWN, wlan_mode);
                kill_all_authentication_daemon(radio, wlan_mode);
				//wds
				for(i=0;i<WDS_VAP_NUM;i++) {
					set_ap_wds_down(radio, i);
				}
//            }
//            else if(WLAN_MODE_STA == wlan_mode)
//            {
//                kill_all_authentication_daemon(radio, wlan_mode);
//                radio_up_down(radio, RADIO_DOWN, wlan_mode);
//            }
            return T_SUCCESS;
        }

//    if(WLAN_MODE_AP == wlan_mode)
//        {
            //Down all the VAPs first
            radio_up_down(radio, RADIO_DOWN, wlan_mode);
            //wds
			for(i=0;i<WDS_VAP_NUM;i++) {
				set_ap_wds_down(radio, i);
			}
            //Kill all the security daemon first
            kill_all_authentication_daemon(radio, wlan_mode);
//        }
//    else if(WLAN_MODE_STA == wlan_mode)
//        {
            //Kill all the security daemon first
//            kill_all_authentication_daemon(radio, wlan_mode);
            //Down all the VAPs first
//            radio_up_down(radio, RADIO_DOWN, wlan_mode);
//        }
    /*net mode and channel*/
    set_ap_wirelessmode_channel(radio);
    /*ap isolation*/
    vap_num = nvram_get_vap_num(radio); 
    //for(i=1; i < vap_num; i++)
    for(i=0; i < vap_num; i++)
	{
        nvram_get_vap_status(radio, i, &vap_enable);
        if(VAP_ENABLE == vap_enable)
            {
				set_ssid(radio, WLAN_MODE_AP, i);//add by frank
				set_acl(radio, i);
				//set_enable_ssid(radio, WLAN_MODE_AP, i);
				set_hidden_ssid(radio, WLAN_MODE_AP, i);//add by frank
				set_bss_isolation(radio, WLAN_MODE_AP, i);//add by frank
				set_ap_security(radio, i);
#if defined(VLAN_ENABLE)
				//Deleted by Mario Huang
				//set_wlan_vlan(radio,i);
                //preserve 3 seconds for main VAP
#endif
                if(0==i) {
					sleep(3);
				}
            }
        else if(VAP_DISABLE == vap_enable)
            {
                //set_disable_ssid(radio, WLAN_MODE_AP, i);
                //vap_up_down(radio, i, WLAN_MODE_AP, VAP_DOWN);
            }		
	}
	set_ap_isolation(radio);//add by frank, impl on 2014-02-17
	//Deleted by Mario Huang 2014-08-12
	//set_ap_wmm(radio, 0);
	//Added by Mario Huang for VLAN test
#if defined(VLAN_ENABLE)
	updateVlan();
#endif
	//wds
	for(i=0;i<WDS_VAP_NUM;i++) {
		set_ap_wds_up(radio, i);
	}
    return T_SUCCESS;
}
예제 #10
0
/* Given the tagged parameter sets from a beacon packet, locate the AP's SSID and return its current channel number */
int parse_beacon_tags(const unsigned char *packet, size_t len)
{
	set_vendor(0, "\0\0\0");
	char *ssid = NULL;
	const unsigned char *tag_data = NULL;
	unsigned char *ie = NULL, *channel_data = NULL;
	size_t ie_len = 0, ie_offset = 0, tag_len = 0, tag_offset = 0;
	int channel = 0;
	struct radio_tap_header *rt_header = NULL;

	rt_header = (struct radio_tap_header *) radio_header(packet, len);
	tag_offset = end_le16toh(rt_header->len) + sizeof(struct dot11_frame_header) + sizeof(struct beacon_management_frame);

	if(tag_offset < len)
	{
		tag_len = (len - tag_offset); /* this actually denotes length of the entire tag data area */
		tag_data = (const unsigned char *) (packet + tag_offset);

		/* If no SSID was manually specified, parse and save the AP SSID */
		if(get_ssid() == NULL)
		{
			ie = parse_ie_data(tag_data, tag_len, (uint8_t) SSID_TAG_NUMBER, &ie_len, &ie_offset);
			if(ie)
			{
				/* Return data is not null terminated; allocate ie_len+1 and memcpy string */
				ssid = malloc(ie_len+1);
				if(ssid)
				{
					memset(ssid, 0, (ie_len+1));
					memcpy(ssid, ie, ie_len);
					set_ssid(ssid);
					free(ssid);
				}

				free(ie);
			}
		}

		ie = parse_ie_data(tag_data, tag_len, HT_CAPS_TAG_NUMBER, &ie_len, &ie_offset);
		if(ie)
		{
			set_ap_htcaps(ie, ie_len);
			free(ie);
		}

		ie = parse_ie_data(tag_data, tag_len, (uint8_t) RATES_TAG_NUMBER, &ie_len, &ie_offset);
		if(ie)
		{
			set_ap_rates(ie, ie_len);
			free(ie);
		}

		ie = parse_ie_data(tag_data, tag_len, (uint8_t) ERATES_TAG_NUMBER, &ie_len, &ie_offset);
		if(ie)
		{
			set_ap_ext_rates(ie, ie_len);
			free(ie);
		}

		channel_data = parse_ie_data(tag_data, tag_len, (uint8_t) CHANNEL_TAG_NUMBER, &ie_len, &ie_offset);
		if(channel_data)
		{
			if(ie_len  == 1)
			{
				channel = *(uint8_t*)channel_data;
			}
			free(channel_data);
		}

		size_t ie_iterator = 0;
		do {
			const unsigned char *tag = tag_data + ie_iterator;
			// check for the length of the tag, and that its not microsoft
			if(tag[0] == VENDOR_SPECIFIC_TAG &&
			   ie_iterator+2+3 < tag_len &&
			   ((tag[1] < 11 && memcmp(tag+2, "\x00\x14\x6c", 3) && memcmp(tag+2, "\x00\x50\xf2", 3)) ||
			    (tag[1] == 30 && !(memcmp(tag+2, "\x00\x26\x86", 3))))) {
				set_vendor(1, tag + 2);
				break;
			}

		} while(get_next_ie(tag_data, tag_len, &ie_iterator));
	}

	return channel;
}