Example #1
0
/**
 * @fn scanWifi
 */
QList<netctlWifiInfo> WpaSup::scanWifi()
{
    if (debug) qDebug() << PDEBUG;

    QList<netctlWifiInfo> scanResults;
    if (!startWpaSupplicant()) {
        stopWpaSupplicant();
        return scanResults;
    }
    if (!wpaCliCall(QString("scan"))) return scanResults;
    waitForProcess(3);

    QStringList rawOutput = getWpaCliOutput(QString("scan_results")).split(QChar('\n'), QString::SkipEmptyParts);
    // remove table header
    rawOutput.removeFirst();
    // remove duplicates
    QStringList rawList;
    QStringList names;
    for (int i=0; i<rawOutput.count(); i++) {
        if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 4) {
            rawList.append(rawOutput[i]);
            continue;
        } else if (rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5) {
            if (names.contains(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4])) continue;
            names.append(rawOutput[i].split(QChar('\t'), QString::SkipEmptyParts)[4]);
            rawList.append(rawOutput[i]);
        }
    }

    for (int i=0; i<rawList.count(); i++) {
        netctlWifiInfo wifiPoint;
        // point name
        if (rawList[i].split(QChar('\t'), QString::SkipEmptyParts).count() == 5)
            wifiPoint.name = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[4];
        else
            wifiPoint.name = QString("<hidden>");
        // profile status
        wifiPoint.active = isProfileActive(wifiPoint.name);
        wifiPoint.exists = isProfileExists(wifiPoint.name);
        // point signal
        wifiPoint.signal = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[2];
        // point security
        QString security = rawList[i].split(QChar('\t'), QString::SkipEmptyParts)[3];
        if (security.contains(QString("WPA2")))
            security = QString("WPA2");
        else if (security.contains(QString("WPA")))
            security = QString("WPA");
        else if (security.contains(QString("WEP")))
            security = QString("WEP");
        else
            security = QString("none");
        wifiPoint.security = security;
        scanResults.append(wifiPoint);
    }
    stopWpaSupplicant();

    return scanResults;
}
Example #2
0
/**
 * @fn startWpaSupplicant
 */
bool WpaSup::startWpaSupplicant()
{
    if (debug) qDebug() << PDEBUG;
    if (ctrlDir.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
        return false;
    }
    if (ctrlGroup.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find group";
        return false;
    }
    if (pidFile.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
        return false;
    }
    if (wpaDrivers.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find drivers";
        return false;
    }
    if (wpaSupPath.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_supplicant";
        return false;
    }
    if (netctlCommand == nullptr) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
        return false;
    }
    QStringList interfaces = netctlCommand->getWirelessInterfaceList();
    if (interfaces.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find interfaces";
        return false;
    }

    if (QFile(pidFile).exists()) return true;
    QString cmd = QString("%1 %2 -B -P \"%3\" -i %4 -D %5 -C \"DIR=%6 GROUP=%7\"")
                    .arg(sudoCommand).arg(wpaSupPath).arg(pidFile).arg(interfaces[0])
                    .arg(wpaDrivers).arg(ctrlDir).arg(ctrlGroup);
    if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
    TaskResult process = runTask(cmd, useSuid);
    waitForProcess(1);
    if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
    if (process.exitCode != 0)
        if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;

    return (process.exitCode == 0);
}
Example #3
0
//Startup function for this program
int init(int argv,char* argc[], char* env[]){
  int i,toReturn;
int* pipefd;
 pid_t* loopBuffer = malloc(sizeof(pid_t)*LOOPS);
 pid_t child; 
char**** broken2 = malloc(sizeof(char***)*1);
int numExecs = breakByDelimiter(broken2,argc,",",argv);
char*** broken = broken2[0];
if(numExecs>1){
 //Allocate pipes: number of pipes = number of execs * 2
 pipefd = malloc(sizeof(int)*2*(numExecs-1));
 //Check for bad pipes
	 /*for(i=0;i<numExecs;i++){
		if(pipe(pipefd + (2*i))<0){
			perror("Couldn't create pipes");
		}
	}*/
	pipe(pipefd);
	}else{
		pipefd = NULL;
	}
	for(i=0;i<numExecs;i++){
		//Create a child
	        child = fork();
		loopBuffer[i] = child;
		
		//Break up function
		toReturn = splitChildren(argv,argc,env,child,i,broken,pipefd,numExecs);
		
	}
	//Close all the pipes
	for(i=0;pipefd!=NULL && i<numExecs;i++){	
			
			close(pipefd[i]);
		
	}
	//Go through all child processes and wait for them to finish
	if(child!=0){	
	waitForProcess(loopBuffer[i],broken,numExecs);
	
	
	}
	return toReturn;
}
Example #4
0
/**
 * @fn wpaCliCall
 */
bool WpaSup::wpaCliCall(const QString commandLine)
{
    if (debug) qDebug() << PDEBUG;
    if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
    if (ctrlDir.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find directory";
        return false;
    }
    if (pidFile.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find PID file";
        return false;
    }
    if (wpaCliPath.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find wpa_cli";
        return false;
    }
    if (netctlCommand == nullptr) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
        return false;
    }
    QStringList interfaces = netctlCommand->getWirelessInterfaceList();
    if (interfaces.isEmpty()) {
        if (debug) qDebug() << PDEBUG << ":" << "Could not find interfaces";
        return false;
    }

    QString interface = interfaces[0];
    QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
            QString(" -P ") + pidFile + QString(" ") + commandLine;
    if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
    TaskResult process = runTask(cmd);
    waitForProcess(1);
    if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
    if (process.exitCode != 0)
        if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;

    return (process.exitCode == 0);
}
Example #5
0
void* inOutThread(void* dataHilo)
{
	int executionSimulator;

	t_dataDispositivo *datos = dataHilo;
	t_nodo_proceso_bloqueadoIO* proceso;

	while (1)
	{

		proceso = waitForProcess(datos);
		debugTrackPCP("[I/O HANDLER] %d process is now using device %s .",
				proceso->proceso->pcb.pid, datos->nombre);
		log_debug(log_kernel,
				"[I/O HANDLER] %d process is now using device %s .",
				proceso->proceso->pcb.pid, datos->nombre);
		executionSimulator = (datos->retardo * proceso->espera) * 1000;
		usleep(executionSimulator);
		debugTrackPCP("[I/O HANDLER] Process has ended I/O.");
		addToReadyQueue(proceso->proceso);
	}
	return NULL ;
}