/* Monitors an interface (or capture file) for WPS data in beacon packets or probe responses */
void monitor(char *bssid, int passive, int source, int channel, int mode)
{
    struct sigaction act;
    struct itimerval timer;
    struct pcap_pkthdr header;
    static int header_printed;
    const u_char *packet = NULL;

    memset(&act, 0, sizeof(struct sigaction));
    memset(&timer, 0, sizeof(struct itimerval));

    /* If we aren't reading from a pcap file, set the interface channel */
    if(source == INTERFACE)
    {
        /*
         * If a channel has been specified, set the interface to that channel.
         * Else, set a recurring 1 second timer that will call sigalrm() and switch to
         * a new channel.
         */
        if(channel > 0)
        {
            change_channel(channel);
        }
        else
        {
            act.sa_handler = sigalrm_handler;
            sigaction (SIGALRM, &act, 0);
            ualarm(CHANNEL_INTERVAL, CHANNEL_INTERVAL);
            change_channel(1);
        }
    }

    if(!header_printed)
    {
		if (o_file_p == 0)
		{
			cprintf(INFO, "BSSID              Channel  RSSI  WPS Version  WPS Locked  ESSID\n");
			cprintf(INFO, "--------------------------------------------------------------------------------------\n");
			header_printed = 1;
		}

    }

    while((packet = next_packet(&header)))
    {
        parse_wps_settings(packet, &header, bssid, passive, mode, source);
#ifndef __APPLE__
        memset((void *) packet, 0, header.len);
#endif
    }

    return;
}
Example #2
0
File: channel.c Project: FFM/horst
int
auto_change_channel(int mon)
{
	int new_chan;
	int ret = 1;
	int start_chan;

	if (the_time.tv_sec == last_channelchange.tv_sec &&
	    (the_time.tv_usec - last_channelchange.tv_usec) < conf.channel_time)
		return 0; /* too early */

	if (conf.do_change_channel) {
		start_chan = new_chan = conf.current_channel;
		do {
			new_chan = new_chan + 1;
			if (new_chan >= conf.num_channels ||
			    new_chan >= MAX_CHANNELS ||
			    (conf.channel_max && new_chan >= conf.channel_max))
				new_chan = 0;

			ret = change_channel(new_chan);

		/* try setting different channels in case we get errors only
		 * on some channels (e.g. ipw2200 reports channel 14 but cannot
		 * be set to use it). stop if we tried all channels */
		} while (ret != 1 && new_chan != start_chan);
	}

	last_channelchange = the_time;
	return ret;
}
Example #3
0
char			*read_all(int fd, fd_set *readf,
				  t_buffs *buffs, char **chan_nick)
{
  t_list                *tmp_cmd;
  int			ret;

  buffs->cmds ? free_content(buffs->cmds) : 0;
  buffs->cmds ? buffs->cmds->destroy(buffs->cmds) : 0;
  buffs->cmds = NULL;
  if (FD_ISSET(fd, readf))
    {
      if ((ret = get_cmd_buff(fd, buffs)) == -1)
	return (NULL);
      else if (ret == -3)
	return (NULL);
      else if (ret == -2)
	puterr("Reply too long\n", 0);
    }
  tmp_cmd = buffs->cmds;
  while (tmp_cmd)
    {
      fprintf(stderr, "%s\n", (char *)tmp_cmd->struc);
      change_channel((char *)tmp_cmd->struc, chan_nick[0], chan_nick[1]);
      tmp_cmd = tmp_cmd->next;
    }
  if (FD_ISSET(0, readf))
    return (get_next_line(0));
  return ("");
}
Example #4
0
/* 
 * Goes to the next 802.11 channel.
 * This is mostly required for APs that hop channels, which usually hop between channels 1, 6, and 11.
 * We just hop channels until we successfully associate with the AP.
 * The AP's actual channel number is parsed and set by parse_beacon_tags() in 80211.c.
 */
int next_channel()
{
        static int i;
	int n = 0;
        int bg_channels[] = BG_CHANNELS;
	int an_channels[] = AN_CHANNELS;
	int *channels = NULL;

	/* Select the appropriate channels for the target 802.11 band */
	if(get_wifi_band() == AN_BAND)
	{
		channels = (int *) &an_channels;
		n = sizeof(an_channels) / sizeof(int);
	}
	else
	{
		channels = (int *) &bg_channels;
		n = sizeof(bg_channels) / sizeof(int);
	}

	/* Only switch channels if fixed channel operation is disabled */
	if(!get_fixed_channel())
	{
        	i++;

        	if((i >= n) || i < 0)
        	{
        	        i = 0;
        	}

        	return change_channel(channels[i]);
	}
	
	return 0;
}
Example #5
0
/* 
 * Waits for a beacon packet from the target AP and populates the globule->ap_capabilities field.
 * This is used for obtaining the capabilities field and AP SSID.
 */
void read_ap_beacon()
{
        struct pcap_pkthdr header;
        const unsigned char *packet = NULL;
        struct radio_tap_header *rt_header = NULL;
        struct dot11_frame_header *frame_header = NULL;
        struct beacon_management_frame *beacon = NULL;
	int channel = 0;
	size_t tag_offset = 0;
	time_t start_time = 0;

	set_ap_capability(0);
	start_time = time(NULL);
	
        while(get_ap_capability() == 0)
        {
                packet = next_packet(&header);
                if(packet == NULL)
                {
                        break;
                }

                if(header.len >= MIN_BEACON_SIZE)
                {
                        rt_header = (struct radio_tap_header *) radio_header(packet, header.len);
			size_t rt_header_len = end_le16toh(rt_header->len);
			frame_header = (struct dot11_frame_header *) (packet + rt_header_len);
			
			if(is_target(frame_header))
			{
                                if((frame_header->fc & end_htole16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
				   end_htole16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON))
                                {
                                       	beacon = (struct beacon_management_frame *) (packet + rt_header_len + sizeof(struct dot11_frame_header));
                                       	set_ap_capability(end_le16toh(beacon->capability));

					/* Obtain the SSID and channel number from the beacon packet */
					tag_offset = rt_header_len + sizeof(struct dot11_frame_header) + sizeof(struct beacon_management_frame);
					channel = parse_beacon_tags(packet, header.len);
					
					/* If no channel was manually specified, switch to the AP's current channel */
					if(!get_fixed_channel() && get_auto_channel_select() && channel > 0 && channel != get_channel())
					{
						change_channel(channel);
						set_channel(channel);
					}

                                       	break;
				}
			}
                }

		/* If we haven't seen any beacon packets from the target within BEACON_WAIT_TIME seconds, try another channel */
		if((time(NULL) - start_time) >= BEACON_WAIT_TIME)
		{
			next_channel();
			start_time = time(NULL);
		}
        }
}
Example #6
0
/* 
 * Waits for a beacon packet from the target AP and populates the globule->ap_capabilities field.
 * This is used for obtaining the capabilities field and AP SSID.
 */
void read_ap_beacon()
{
    struct pcap_pkthdr header;
    const u_char *packet = NULL;
    struct radio_tap_header *rt_header = NULL;
    struct dot11_frame_header *frame_header = NULL;
    struct beacon_management_frame *beacon = NULL;
    int channel = 0;
    time_t start_time = 0;

    set_ap_capability(0);
    start_time = time(NULL);

    while(get_ap_capability() == 0)
    {
        packet = next_packet(&header);
        if(packet == NULL)
        {
            break;
        }

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

            if(is_target(frame_header))
            {
                if(frame_header->fc.type == MANAGEMENT_FRAME && frame_header->fc.sub_type == SUBTYPE_BEACON)
                {
                    beacon = (struct beacon_management_frame *) (packet + rt_header->len + sizeof(struct dot11_frame_header));
                    set_ap_capability(beacon->capability);

                    /* Obtain the SSID and channel number from the beacon packet */
                    channel = parse_beacon_tags(packet, header.len);

                    /* If no channel was manually specified, switch to the AP's current channel */
                    if(!get_fixed_channel() && get_auto_channel_select() && channel > 0 && channel != get_channel())
                    {
                        change_channel(channel);
                        set_channel(channel);
                    }

                    break;
                }
            }
        }

        /* If we haven't seen any beacon packets from the target within BEACON_WAIT_TIME seconds, try another channel */
        if((time(NULL) - start_time) >= BEACON_WAIT_TIME)
        {
            next_channel();
            start_time = time(NULL);
        }
    }
}
Example #7
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;

	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;
	}
Example #8
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);
							
						}
						
					}
Example #9
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;
}
Example #10
0
static PRESULT win_progname_unkown_act_proc(VACTION act)
{
	PRESULT ret = PROC_LOOP;
	
	INT32 shift;
	UINT8 av_mode,back_saved;
	UINT16  channel;
	UINT16 strID;

#ifdef DVR_PVR_SUPPORT
	if(api_pvr_is_recording())
	{
		if( act != VACT_CH_UP && act != VACT_CH_DOWN)
		{
			return ret;
		}
	}
#endif

	api_stop_timer(&progname_timer);

	shift = -1;
	switch(act)
	{	
	case VACT_CH_UP:
		shift = 1;
	case VACT_CH_DOWN:
		change_channel(shift);
		break;
	case VACT_GRP_UP:
		shift = 1;
	case VACT_GRP_DOWN:
		change_group(shift);
		break;
	case VACT_FCH_UP:
		shift = 1;
	case VACT_FCH_DOWN:
		change_fav_channel(shift);
		break;		
	case VACT_TV_RADIO_SW:
		av_mode = sys_data_get_cur_chan_mode();
		av_mode = (av_mode==TV_CHAN)? RADIO_CHAN : TV_CHAN; 				
		sys_data_get_cur_group_channel(&channel, av_mode);
		if(channel==P_INVALID_ID) /* If the opposite mode has no channel */
		{
			if(av_mode==RADIO_CHAN)
                strID = RS_MSG_NO_RADIO_CHANNEL;
            else
                strID = RS_MSG_NO_TV_CHANNEL;            
		win_compopup_init(WIN_POPUP_TYPE_SMSG);
		win_compopup_set_msg(NULL, NULL,strID);
		win_compopup_open_ext(&back_saved);
		osal_task_sleep(500);
		win_compopup_smsg_restoreback();
		}
		else
		{
#ifndef NEW_DEMO_FRAME
            UIChChgStopProg(TRUE);
#endif
			sys_data_set_cur_chan_mode(av_mode);
			change_group(0);
		}
		break;
	case VACT_RECALL:
		channel = recall_play_channel(0);
		if(channel != P_INVALID_ID)
			api_play_channel(channel, TRUE, TRUE,FALSE);	
		break;
	case VACT_POP_DETAIL:
		b_popdetail = TRUE;
		ret  = PROC_LEAVE;
		break;
	default:
		break;
	}

	win_progname_redraw();

	progname_timer = api_start_timer(PROGNAME_TIMER_NAME,PROGNAME_TIMER_TIME,progname_timer_func);

	return ret;
}
Example #11
0
static PRESULT win_progname_unkown_act_proc(VACTION act)
{
	PRESULT ret = PROC_LOOP;

	INT32 shift;
	UINT8 av_mode, back_saved;
	UINT16 channel;
	UINT16 strID;
#ifdef AD_SANZHOU
	P_NODE pnode;
#endif

	api_stop_timer(&progname_timer);
#ifdef MULTI_CAS
#if(CAS_TYPE==CAS_IRDETO)
			if(getStopChannelChange()&&(act!=VACT_RECALL&&act!=VACT_SCHEDULE))//check whether stop channel change
				return ret;
#endif
#endif
	shift =  - 1;
	switch (act)
	{
		case VACT_CH_UP:
			shift = 1;
		case VACT_CH_DOWN:
			change_channel(shift);
		#ifdef MIS_AD
			MIS_ShowEpgAdv(0);
		#endif
			break;
		case VACT_GRP_UP:
			shift = 1;
		case VACT_GRP_DOWN:
			change_group(shift);
			break;
		case VACT_FCH_UP:
			shift = 1;
		case VACT_FCH_DOWN:
			change_fav_channel(shift);
			break;
		case VACT_TV_RADIO_SW:
			av_mode = sys_data_get_cur_chan_mode();
			av_mode = (av_mode == TV_CHAN) ? RADIO_CHAN : TV_CHAN;
			//sys_data_set_cur_intgroup_index(0); /*force to return all group*/
			sys_data_get_group_channel(0, &channel, av_mode);
			if (channel == P_INVALID_ID)
			{	
				 /* If the opposite mode has no channel */
				win_compopup_init(WIN_POPUP_TYPE_SMSG);
				if(av_mode == TV_CHAN)
				{
					win_compopup_set_msg(NULL, NULL, RS_MSG_NO_PROGRAM_TV);
				}
				else
				{
					win_compopup_set_msg(NULL, NULL, RS_MSG_NO_RADIO_CHANNEL);
				}
				win_compopup_open_ext(&back_saved);
				osal_task_sleep(1000);
				win_compopup_smsg_restoreback();
#ifdef MULTI_CAS
#if(CAS_TYPE==CAS_CONAX)
				if(get_mmi_msg_cnt()>0)
				{
					ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_MCAS, 0, FALSE);
					MMI_PRINTF("CTRL_MSG_SUBTYPE_STATUS_MCAS: tv/radio; code:%d\n",0);
					set_mmi_showed(10);
				}
#endif
#endif
			}
			else
			{
				sys_data_set_cur_chan_mode(av_mode);
				change_group(0);
			}
			break;
		case VACT_RECALL:
			channel = recall_play_channel(0);
			if (channel != P_INVALID_ID)
			{
#ifdef MULTI_CAS
#if(CAS_TYPE==CAS_CONAX)
				/*clean msg*/
				clean_mmi_msg(1, TRUE);
				clean_mmi_msg(3, TRUE);
				clean_mmi_msg(4, TRUE);
				clean_mmi_msg(6, TRUE);
				if(get_mmi_showed()==1||get_mmi_showed()==6)
					win_mmipopup_close();
				if(get_mmi_showed()!=5)
					set_mmi_showed(10);
#endif
#endif		
				api_play_channel(channel, TRUE, TRUE, FALSE);
#ifdef AD_SANZHOU
				if(get_prog_at(channel, &pnode) == SUCCESS)
				{
					szxc_ad_hide_txt();
					szxc_ad_show_txt(pnode.prog_number);
					szxc_ad_hide_pic(AD_BANNER);
					szxc_ad_show_banner(pnode.prog_number,banner_pic_rt);
				}
#endif
			}
#ifdef MULTI_CAS
#if(CAS_TYPE==CAS_CONAX)
			else if(get_mmi_msg_cnt()>0)
			{
				ap_send_msg(CTRL_MSG_SUBTYPE_STATUS_MCAS, 0, FALSE);
				MMI_PRINTF("CTRL_MSG_SUBTYPE_STATUS_MCAS: recall; code:%d\n",0);
				set_mmi_showed(10);
			}
#endif
#endif				
			#ifdef MIS_AD		
			MIS_ShowEpgAdv(0);
			#endif
			break;
		case VACT_SCHEDULE:
			api_stop_timer(&progname_timer);
			//close the mini_epg
			ap_send_msg(CTRL_MSG_SUBTYPE_CMD_EXIT, 1, TRUE);
			//open the schedule
			//		ap_send_msg(CTRL_MSG_SUBTYPE_CMD_ENTER_ROOT, (UINT32)(POBJECT_HEAD)&g_win_schedule, TRUE);
			break;
		default:
			;
	}

#ifdef MULTI_CAS
#if(CAS_TYPE==CAS_CDCA)
	show_finger_print(0, 0);
#elif(CAS_TYPE==CAS_DVT)
	ap_cas_fingerprint_proc(0, 1);
#endif
#endif
	win_progname_redraw(TRUE);

	progname_timer = api_start_timer(PROGNAME_TIMER_NAME, PROGNAME_TIMER_TIME, progname_timer_func);
#ifdef MIS_AD
	Mis_Set_SameChan_AdvShowOnce(TRUE);
	Mis_Set_EnterAutoShow(FALSE);
#endif
	return ret;

}
Example #12
0
// finish a connection event
//
// 1) update the anchor point (see details below)
// 2) increment connection event counter
// 3) check if supervision timeout is exceeded
// 4) setup radio for next packet (data or adv if timeout exceeded)
//
// anchor update logic can be summarized thusly:
// 1) if we received two packets, set the connection anchor to the
//    observed value
// 2) if we received one packet, see if it's within ANCHOR_EPISLON
//    microseconds if the expected anchor time. if so, it's the master
//    and we can update the anchor
// 3) if the single packet is a slave or we received zero packets,
//    update the anchor to the estimated value
//
// FIXME this code does not properly handle the case where the initial
// connection transmit window has no received packets
static void finish_conn_event(void) {
	uint32_t last_anchor = 0;
	int last_anchor_set = 0;

	// two packets -- update anchor
	if (conn_event.num_packets == 2) {
		last_anchor = conn_event.anchor;
		last_anchor_set = 1;
	}

	// if there's one packet, we need to find out if it was the master
	else if (conn_event.num_packets == 1 && conn.anchor_set) {
		// calculate the difference between the estimated and observed anchor
		uint32_t estimated_anchor = conn.last_anchor + conn.conn_interval;
		uint32_t delta = estimated_anchor - conn_event.anchor;
		// see whether the observed anchor is within 3 us of the estimate
		delta += ANCHOR_EPSILON;
		if (delta < 2 * ANCHOR_EPSILON) {
			last_anchor = conn_event.anchor;
			last_anchor_set = 1;
		}
	}

	// if we observed a new anchor, set it
	if (last_anchor_set) {
		conn.last_anchor = last_anchor;
		conn.anchor_set = 1;
	}

	// without a new anchor, estimate the next anchor
	else if (conn.anchor_set) {
		conn.last_anchor += conn.conn_interval;
	}

	else {
		// FIXME this is totally broken if we receive the slave's packet first
		conn.last_anchor = conn_event.anchor;
		conn.last_packet_ts = NOW; // FIXME gross hack
	}

	// update last packet for supervision timeout
	if (conn_event.num_packets > 0) {
		conn.last_packet_ts = NOW;
	}

	reset_conn_event();

	// increment connection event counter
	++conn.conn_event_counter;

	// supervision timeout reached - switch back to advertising
	if (NOW - conn.last_packet_ts > conn.supervision_timeout) {
		reset_conn();
		change_channel();
	}

	// FIXME - hack to cancel following a connection
	else if (cancel_follow) {
		cancel_follow = 0;
		reset_conn();
		change_channel();
	}

	// supervision timeout not reached - hop to next channel
	else {
		timer1_set_match(conn.last_anchor + conn.conn_interval - RX_WARMUP_TIME);
	}
}
Example #13
0
int main(int argc, char *argv[]) {

	SDL_Event event;
	VideoState *is;
	int i;
	puts("start");
	global_mutex_lock = SDL_CreateMutex();

	is = av_mallocz(sizeof(VideoState));
	if (argc < 2){
		fprintf(stderr, "Usage: test <file>\n");
		exit(1);
	}
		
	av_register_all();		// Register all formats and codecs
	puts("avregister");
	//if (av_register_protocol(&e2URLProtocol) < 0){
	//	printf("Error - URL protocol \n");
	//	exit(-1)
	//}
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER)){
		fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
		exit(1);
	}
	for(i=0; i<MAX_CHANNELS;i++){
		// Make a screen to put our video
		#ifndef __DARWIN__
		screen[i] = SDL_SetVideoMode(640, 480, 0, 0);
		#else
		screen[i] = SDL_SetVideoMode(640, 480, 24, 0);
		#endif
		if (!screen[i]){
			fprintf(stderr, "SDL: could not set video mode - exiting\n");
			exit(1);
		}
	}
	for(i=0; i<MAX_CHANNELS;i++){
		global_video_state[i] = av_mallocz(sizeof(VideoState));
		global_video_state[i]->videoIndex = i;
		puts("screen created");
		printf("i is: %d\n",i);
		av_strlcpy(global_video_state[i]->filename, argv[i+1], sizeof(global_video_state[i]->filename));
		puts("avstrlcpy");	
		global_video_state[i]->pictq_mutex = SDL_CreateMutex();
		global_video_state[i]->pictq_cond = SDL_CreateCond();
		schedule_refresh(global_video_state[i], 40);
		global_video_state[i]->av_sync_type = DEFAULT_AV_SYNC_TYPE;
		global_video_state[i]->parse_tid = SDL_CreateThread(decode_thread, global_video_state[i]);
		puts("main var created");
		if (!global_video_state[i]->parse_tid) {
			av_free(global_video_state[i]);
			return -1;
		}
	}
	av_init_packet(&f_pkt);
	puts("av_init_packet");
	f_pkt.data = (unsigned char*)"FLUSH";

	for (;;) {
		double inc , pos;
		SDL_WaitEvent(&event);
		switch (event.type) {
			case SDL_KEYDOWN:
				switch (event.key.keysym.sym) {
					case SDLK_LEFT:
						inc = -10.0;
						goto do_seek;
					case SDLK_RIGHT:
						inc = 10.0;
						goto do_seek;
					case SDLK_UP:
						inc = 60.0;
						goto do_seek;
					case SDLK_DOWN:
						inc = -60.0;
						goto do_seek;
					do_seek:
						SDL_LockMutex(global_mutex_lock);
						if (global_video_state[global_videoIndex]){
							pos = get_master_clock(global_video_state[global_videoIndex]);
							pos += inc;
							stream_seek(global_video_state[global_videoIndex],(int64_t)(pos *AV_TIME_BASE),inc);
						}
						SDL_UnlockMutex(global_mutex_lock);
						break;
					case SDLK_b:
						global_video_state[global_videoIndex]->color_req = 'b';
						break;
					case SDLK_r:
						global_video_state[global_videoIndex]->color_req = 'r';
						break;
					case SDLK_g:
						global_video_state[global_videoIndex]->color_req = 'g';
						break;
					case SDLK_w:
						global_video_state[global_videoIndex]->color_req = 'w';
						break;
					case SDLK_n:
						global_video_state[global_videoIndex]->color_req = 'n';
						break;
					case SDLK_1:
						change_channel(1);
						break;
					case SDLK_2:
						change_channel(2);
						break;
					case SDLK_3:
						change_channel(3);
						break;
					case SDLK_4:
						change_vidchannel(1);
						break;
					case SDLK_5:
						change_vidchannel(2);
						break;
					case SDLK_6:
						change_vidchannel(3);
						break;
					case SDLK_7:
						change_audchannel(1);
						break;
					case SDLK_8:
						change_audchannel(2);
						break;
					case SDLK_9:
						change_audchannel(3);
						break;
				default:
					break;
				}
				break;
			case FF_QUIT_EVENT:
				case SDL_QUIT:
					for(i=0; i<MAX_CHANNELS; i++){
						global_video_state[i]->quit = 1;
						SDL_CondSignal(global_video_state[i]->audioq.cond);
						SDL_CondSignal(global_video_state[i]->videoq.cond);
					}
					SDL_Quit();
					exit(0);
					break;
				case FF_ALLOC_EVENT:
					alloc_picture(event.user.data1);
					break;
				case FF_REFRESH_EVENT:
					video_refresh_timer(event.user.data1);
					break;
			default:
				break;
		}
	}
	return 0;

}