Exemplo n.º 1
0
static void
select_net(struct cm* cm)
{
        struct wl_network_t *candidate_net;
        struct wl_network_t *current_net;
        struct wl_ssid_t *ssid_p;

        int ret;

        /* Nothing to do */
        if (0 == cm->candidate.ssid.len) {
                return;
        }
        
        current_net = wl_get_current_network();
        candidate_net = find_best_candidate(cm);

        /* Connected to the candidate? ... */
        if ( current_net == candidate_net ) {
                if ( current_net ) {
                        /* ...yes, dont change. */
                        
                        return;
                }
        }

        /* Roaming checks */
        if (current_net && candidate_net) {
                /* Are we changing BSSs? */
                if ( equal_ssid(&candidate_net->ssid, 
                                &current_net->ssid)) {

                        /* ...no. Does the currently connected
                         * net have a decent RSSI?...*/
                        if ( current_net->rssi > ROAMING_RSSI_THRESHOLD ) {
                                /* ...yes, stay with it. */
                                return;
                        }
                        /* ...no. Does the candidate have
                         * sufficiently better RSSI to
                         * motivate a switch to it? */
                        if ( candidate_net->rssi < current_net->rssi + 
                             ROAMING_RSSI_DIFF) {
                                return;
                        }
                        /* ...yes, try to roam to candidate_net */
                        CM_DPRINTF("CM: Roaming from rssi %d to %d\n",
                                   current_net->rssi,
                                   candidate_net->rssi);
                }
        }
        /* a candidate is found */
        if (candidate_net) {
                /* We connect to a specific bssid here because
                 * find_best_candidate() might have picked a
                 * particulare AP among many with the same SSID.
                 * wl_connect() would pick one of them at random.
                 */
                ret = wl_connect_bssid(candidate_net->bssid);
        }
        /* no candidate found */
        else {
                CM_DPRINTF("CM: No candidate found for ssid \"%s\"\n",
                           ssid2str(&cm->candidate.ssid));
                /* Might be a hidden SSID so we try to connect to it.
                 * wl_connect() will trigger a directed scan
                 * for the SSID in this case.
                 */
                ssid_p = &cm->candidate.ssid;
                ret = wl_connect(ssid_p->ssid, ssid_p->len);
        }
        switch (ret) {
        case WL_SUCCESS :
                return;
        case WL_BUSY:
                wl_disconnect();
                return;
        case WL_RETRY:
                break;
        default :
                CM_DPRINTF("CM: failed to connect\n");
                break;
        } 
                
        /* some operation failed or no candidate found */
        if (wl_scan() != WL_SUCCESS)
                CM_DPRINTF("CM: failed to scan\n");                
}
Exemplo n.º 2
0
 void join_map()
{
  double current_start_lat, current_start_lon;
  double current_end_lat, current_end_lon;
  int ipoints, ios;
  cdb_edit_join_method join_method = JOIN_NO_METHOD;
  cdb_index_entry *best_candidate = NULL;
  
  int reversed_current_segment = 0, appended_candidate = 0;

  if (verbose) fprintf(stderr,"> Starting joins.\n");
  
  new_file = NULL;
  new_file = fopen(joined_filename, "w");
  if (NULL == new_file) {perror(new_filename); error_exit(usage); }
  ios = fwrite(dest->header, 1, CDB_FILE_HEADER_SIZE, new_file);
  if (very_verbose) fprintf(stderr,">>wrote %d bytes for header.\n",ios);
  if (ios != CDB_FILE_HEADER_SIZE)
  { fprintf(stderr,"cdb_edit: error writing header.\n");
    perror(new_filename);
    exit(ABORT);
  }
  
    
/*
 *     get rank
 */
    
  if (source->header->segment_rank > dest->header->segment_rank)
    dest->header->segment_rank = source->header->segment_rank;

/*
 *	step thru segment dictionary entries
 */

  if(verbose && !very_verbose)
    fprintf(stderr,"> new : appended\n");

  for(reset_current_seg_cdb(source); 
      source->segment < last_segment_cdb(source); 
      next_segment_cdb(source))
  {
    current_segment = source->segment;
    if((byte4)NULL == current_segment->addr)
      continue;

/*
 *   Get start and end of current segment
 */
    load_current_seg_data_cdb(source);

    current_start_lat = (double)source->segment->ilat0 * CDB_LAT_SCALE;
    current_start_lon = (double)source->segment->ilon0 * CDB_LON_SCALE;
    
    move_pu(current_start_lat, current_start_lon);
    
    current_end_lat = current_start_lat;
    current_end_lon = current_start_lon;
    
    for(ipoints = 0; ipoints < source->npoints;
	ipoints++, source->data_ptr++)
    {
      current_end_lat += (double) source->data_ptr->dlat * CDB_LAT_SCALE;
      current_end_lon += (double) source->data_ptr->dlon * CDB_LON_SCALE;
      draw_pd(current_end_lat, current_end_lon);
    }

/*
 *    Get start and end coordinates
 */ 
    forward_mapx(map, current_start_lat, current_start_lon, 
		 &current_x_start, &current_y_start);
    forward_mapx(map, current_end_lat, current_end_lon, 
		 &current_x_end, &current_y_end);
    
    if (very_verbose) fprintf(stderr,"> joining to old segment %d.\n",
			      source->segment->ID);
    else if(verbose) 
      {
	if(0 == dest->seg_count % 15)
	  fprintf(stderr,"\n\n> new : appended\n");
	fprintf(stderr,"\n> %d : ", dest->seg_count);
      }
/*
 *    check all later segments to find best candidate for joining (if any)
 */
    if (very_very_verbose) fprintf(stderr,">>> Searching candidates.\n");
    
    join_method = JOIN_NO_METHOD;
    best_candidate = NULL;

    best_candidate = find_best_candidate(&join_method);
   
/*
 *       Join the best candidate to the current segment
 */

    while(NULL != best_candidate)
    {
      set_current_seg_cdb(source, best_candidate);
      load_current_seg_data_cdb(source);
      if(verbose) fprintf(stderr,"%d ", source->segment->ID);
      
      switch(join_method)
      {
      case JOIN_START_TO_START:
	reverse_current_segment();             
	reversed_current_segment++;
	append_candidate(FALSE, &current_x_start, &current_y_start,
			 &current_x_end, &current_y_end);
	appended_candidate++;
	break;
      case JOIN_START_TO_END:
	reverse_current_segment();             reversed_current_segment++;
	append_candidate(TRUE, &current_x_start, &current_y_start,
			 &current_x_end, &current_y_end);
	appended_candidate++;
	break;
      case JOIN_END_TO_START:
	append_candidate(FALSE, &current_x_start, &current_y_start,
			 &current_x_end, &current_y_end);
	appended_candidate++;
	break;
      case JOIN_END_TO_END:
	append_candidate(TRUE, &current_x_start, &current_y_start,
			 &current_x_end, &current_y_end);
	appended_candidate++;
	break;     
      default:
	fprintf(stderr, "fatal error : join method not set.");
	exit(ABORT);
      }                                         /* end case */

/*
 *     try to find another candidate
 */
      
      set_current_seg_cdb(source, current_segment);
      join_method = JOIN_NO_METHOD;
      best_candidate = NULL;
      best_candidate = find_best_candidate(&join_method);
      
    }                                           /* end while loop */
    
    set_current_seg_cdb(source, current_segment);
    
  }                                          /* end current loop */
  
/*
 *	flush segment data buffer and finish
 */

  if(verbose)
  {
    fprintf(stderr, "\n> reversed current segment %d times.",
	    reversed_current_segment);
    fprintf(stderr, "\n> appended %d segments.", appended_candidate);
  }
  
  if (dest->npoints > 0) write_segment_data(dest->seg_count);
  
  finish_new_file();
  
  return;
}