def handle_set_mac(self,mac):
     """
     Set the MAC Address of the Wifi Device
     """
     if(sofi_iftools.isRoot()):
         return sofi_iftools.setLinuxMAC(WIFI_INTERFACE, sofi_iftools.sanitizeMac(mac))
     else:
         return False
Exemple #2
0
 def handle_set_mac(self, mac):
     """
     Set the MAC Address of the Wifi Device
     """
     if (sofi_iftools.isRoot()):
         return sofi_iftools.setLinuxMAC(WIFI_INTERFACE,
                                         sofi_iftools.sanitizeMac(mac))
     else:
         return False
Exemple #3
0
    def listen(self):
        """
        Listen for incoming service requests and provide as necessary.
        """
        self.init_sockets()
        self.dnsmasq = pwifi_dnsmasq.DnsmasqCTRL()
        self.dnsmasq.start()
        self.webserver = sofi_web.sofi_web(self.database,self.stateIndex)
        
        while True:
            logging.info("Waiting for messages...")
            data, addr = self.receive_msg()
            s = addr
            if s is None:
                s = "hostapd"
            logging.info("Received message from %s: %s" % (s, data))

            split_data = data.split()
            ssid = split_data[-1]
            request = split_data[0]
            source_address = sofi_iftools.sanitizeMac(split_data[1]) #source_address MAC
            # Requests from legacy clients only contain the request keyword
            # and SSID. Requests from hostapd provide the IP address which
            # will be used for the BSS as well.
            ip = None
            if len(split_data) == 4:
                ip = split_data[2]

            if(sofi_ssid.isSofiSSID(ssid)):
                ssidObject = sofi_ssid.ssid(SSID=ssid)
                if request == IPC.PWIFI_IPC_REQUEST:
                    reply = self.handle_request(ssidObject,source_address, ip=ip)
                    if len(reply) != 0:
                        if addr is None:
                            logging.info("Sending reply to hostapd: %s" %reply)
                            logging.info("Hex encoded reply: %s" %(sofi_crypt.hex(reply))) 
                            self.sock_hostapd.sendto(reply, IPC.PWIFI_HOSTAPD_INTERFACE)
                        else:
                            logging.info("Sending reply to legacy client " + addr)
                            self.sock_legacy.sendto(reply, addr)
                    else:
                        logging.info("Empty reply. Not sending a reply.")
                elif request == IPC.PWIFI_IPC_DISBAND:
                    reply = self.handle_disband(ssidObject,source_address)
                    # hostapd does not expect a reply on disband messages -> reply is empty String
                else:
                    logging.error("Invalid message format. Ignored: %s" %data)
                    continue
            else:
                logging.error("Not a valid SSID! Ignored!")
                continue