Exemplo n.º 1
0
/*******************************************************************************
 *	parse_config()
 *******************************************************************************
 *
 *  DESCRIPTION:
 *
 *      This function opens the device's config file and parses the options from
 *   it, so that it can properly configure itself. If no configuration file
 *   or configuration is present, then continue to use the options already
 *   parsed from config.opts or wireless.opts.
 *
 *  PARAMETERS:
 *
 *      dev - a pointer to the device's net_device structure
 *
 *  RETURNS:
 *
 *      N/A
 *
 ******************************************************************************/
void parse_config(struct net_device *dev)
{
	int				    file_desc;
#if 0 /* BIN_DL */
	int				rc;
	char				*cp = NULL;
#endif /* BIN_DL */
	char                buffer[MAX_LINE_SIZE];
	char                filename[MAX_LINE_SIZE];
	mm_segment_t	    fs;
	struct wl_private   *wvlan_config = NULL;
	ENCSTRCT            sEncryption;
	/*------------------------------------------------------------------------*/

	DBG_FUNC("parse_config");
	DBG_ENTER(DbgInfo);

	/* Get the wavelan specific info for this device */
	wvlan_config = dev->priv;
	if (wvlan_config == NULL) {
		DBG_ERROR(DbgInfo, "Wavelan specific info struct not present?\n");
		return;
	}

	/* setup the default encryption string */
	strcpy(wvlan_config->szEncryption, DEF_CRYPT_STR);

	/* Obtain a user-space process context, storing the original context */
	fs = get_fs();
	set_fs(get_ds());

	/* Determine the filename for this device and attempt to open it */
	sprintf(filename, "%s%s", ROOT_CONFIG_FILENAME, dev->name);
	file_desc = open(filename, O_RDONLY, 0);
	if (file_desc != -1) {
		DBG_TRACE(DbgInfo, "Wireless config file found. Parsing options...\n");

		/* Read out the options */
		while (readline(file_desc, buffer))
			translate_option(buffer, wvlan_config);
		/* Close the file */
		close(file_desc);	/* ;?even if file_desc == -1 ??? */
	} else {
		DBG_TRACE(DbgInfo, "No iwconfig file found for this device; "
				   "config.opts or wireless.opts will be used\n");
	}
	/* Return to the original context */
	set_fs(fs);

	/* convert the WEP keys, if read in as key1, key2, type of data */
	if (wvlan_config->EnableEncryption) {
		memset(&sEncryption, 0, sizeof(sEncryption));

		wl_wep_decode(CRYPT_CODE, &sEncryption,
						   wvlan_config->szEncryption);

		/* the Linux driver likes to use 1-4 for the key IDs, and then
		   convert to 0-3 when sending to the card.  The Windows code
		   base used 0-3 in the API DLL, which was ported to Linux.  For
		   the sake of the user experience, we decided to keep 0-3 as the
		   numbers used in the DLL; and will perform the +1 conversion here.
		   We could have converted  the entire Linux driver, but this is
		   less obtrusive.  This may be a "todo" to convert the whole driver */
		sEncryption.wEnabled = wvlan_config->EnableEncryption;
		sEncryption.wTxKeyID = wvlan_config->TransmitKeyID - 1;

		memcpy(&sEncryption.EncStr, &wvlan_config->DefaultKeys,
				sizeof(CFG_DEFAULT_KEYS_STRCT));

		memset(wvlan_config->szEncryption, 0, sizeof(wvlan_config->szEncryption));

		wl_wep_code(CRYPT_CODE, wvlan_config->szEncryption, &sEncryption,
						 sizeof(sEncryption));
	}

	/* decode the encryption string for the call to wl_commit() */
	wl_wep_decode(CRYPT_CODE, &sEncryption, wvlan_config->szEncryption);

	wvlan_config->TransmitKeyID    = sEncryption.wTxKeyID + 1;
	wvlan_config->EnableEncryption = sEncryption.wEnabled;

	memcpy(&wvlan_config->DefaultKeys, &sEncryption.EncStr,
			sizeof(CFG_DEFAULT_KEYS_STRCT));

#if 0 /* BIN_DL */
		/* Obtain a user-space process context, storing the original context */
		fs = get_fs();
		set_fs(get_ds());

		/* ;?just to fake something */
		strcpy(/*wvlan_config->fw_image_*/filename, "/etc/agere/fw.bin");
		file_desc = open(/*wvlan_config->fw_image_*/filename, 0, 0);
		if (file_desc == -1) {
			DBG_ERROR(DbgInfo, "No image file found\n");
		} else {
			DBG_TRACE(DbgInfo, "F/W image file found\n");
#define DHF_ALLOC_SIZE 96000			/* just below 96K, let's hope it suffices for now and for the future */
			cp = (char *)vmalloc(DHF_ALLOC_SIZE);
			if (cp == NULL) {
				DBG_ERROR(DbgInfo, "error in vmalloc\n");
			} else {
				rc = read(file_desc, cp, DHF_ALLOC_SIZE);
				if (rc == DHF_ALLOC_SIZE) {
					DBG_ERROR(DbgInfo, "buffer too small, %d\n", DHF_ALLOC_SIZE);
				} else if (rc > 0) {
					DBG_TRACE(DbgInfo, "read O.K.: %d bytes  %.12s\n", rc, cp);
					rc = read(file_desc, &cp[rc], 1);
					if (rc == 0)
						DBG_TRACE(DbgInfo, "no more to read\n");
				}
				if (rc != 0) {
					DBG_ERROR(DbgInfo, "file not read in one swoop or other error"\
										", give up, too complicated, rc = %0X\n", rc);
				}
				vfree(cp);
			}
			close(file_desc);
		}
		set_fs(fs);			/* Return to the original context */
#endif /* BIN_DL */

	DBG_LEAVE(DbgInfo);
	return;
} /* parse_config */
int main(const int argc, const char* const argv[]) {

  if (argc != 2 and argc != 3) {
    std::cerr << err << "Exactly one input is required,\n"
      " the name of the file with the clause-set in DIMACS-format.\n"
      "One may also specify additionally \"n\", \"ni\" or \"f\" to force \n"
      "removal of all zeroes, leading and trailing zeroes or no removal of\n"
      "zeroes from statistics output.\n"
      "However, the actual number of input parameters was " << argc-1 << ".\n";
    return error_parameters;
  }

  const std::string shg_input_filepath = argv[1];
  std::ifstream shg_inputfile(shg_input_filepath.c_str());
  if (not shg_inputfile) {
    std::cerr << err << "Failure opening input file " << shg_input_filepath << ".\n";
    return error_openfile;
  }

  typedef OKlib::InputOutput::RawDimacsCLSAdaptor<> CLSAdaptor;
  CLSAdaptor cls_F;
  typedef OKlib::InputOutput::StandardDIMACSInput<CLSAdaptor> CLSInput;
  const CLSInput input_F(shg_inputfile, cls_F);
  shg_inputfile.close();

  // Compute the prime clauses:
  typedef OKlib::Satisfiability::FiniteFunctions::QuineMcCluskey<num_vars>::clause_set_type clause_set_type;
  const clause_set_type prime_imp_F = OKlib::Satisfiability::FiniteFunctions::quine_mccluskey<num_vars>(cls_F.clause_set);

  // Compute the subsumption hypergraph:
  typedef OKlib::SetAlgorithms::Subsumption_hypergraph<clause_set_type, CLSAdaptor::clause_set_type>::set_system_type subsumption_hg_type;
  subsumption_hg_type subsumption_hg = 
    OKlib::SetAlgorithms::subsumption_hypergraph(prime_imp_F, cls_F.clause_set);
  std::sort(subsumption_hg.begin(), subsumption_hg.end());
  subsumption_hg.erase(std::unique(subsumption_hg.begin(), subsumption_hg.end()), subsumption_hg.end());

  // Compute statistics and output to file
  
  typedef OKlib::InputOutput::CLSAdaptorFullStatistics<> StatsCLSAdaptor;
  typedef OKlib::InputOutput::ListTransfer<StatsCLSAdaptor > List2Statistics;

  // Do we want full output or to remove leading and trailing zeroes:
  StatsCLSAdaptor shg_stats;
  StatsCLSAdaptor prime_stats;
  if (argc > 2) {
    const output_options opt = translate_option(argv[2]);
    if (opt != (output_options) 0) {
      shg_stats.stat.option = opt;
      prime_stats.stat.option = opt;
    }
    else {
      std::cerr << err << "If an option is given, it must be one of \"n\", \"ni\" or \"f\".\n";
      return(error_parameters);
    }
  }
  else {
    shg_stats.stat.option = default_option;
    prime_stats.stat.option = default_option;
  }
  

  List2Statistics(subsumption_hg, shg_stats, "");
  const std::string shg_input_filename = boost::filesystem::path(shg_input_filepath).filename().string();
  const std::string shg_stats_filename = shg_input_filename + "_shg_stats";
  std::ofstream shg_stats_outputfile(shg_stats_filename.c_str());
  shg_stats_outputfile << shg_stats.stat << "\n";   

  List2Statistics(prime_imp_F, prime_stats, "");
  
  const std::string primes_stats_filename = shg_input_filename + "_primes_stats";
  std::ofstream primes_stats_outputfile(primes_stats_filename.c_str());
  primes_stats_outputfile << prime_stats.stat << "\n";

}