1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326 |
- # wpa_supplicant D-Bus interface tests
- # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
- #
- # This software may be distributed under the terms of the BSD license.
- # See README for more details.
- import binascii
- import logging
- logger = logging.getLogger()
- import subprocess
- import time
- try:
- import gobject
- import dbus
- dbus_imported = True
- except ImportError:
- dbus_imported = False
- import hostapd
- from wpasupplicant import WpaSupplicant
- from utils import HwsimSkip, alloc_fail, fail_test
- from p2p_utils import *
- from test_ap_tdls import connect_2sta_open
- from test_ap_eap import check_altsubject_match_support
- from test_nfc_p2p import set_ip_addr_info
- WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
- WPAS_DBUS_PATH = "/fi/w1/wpa_supplicant1"
- WPAS_DBUS_IFACE = "fi.w1.wpa_supplicant1.Interface"
- WPAS_DBUS_IFACE_WPS = WPAS_DBUS_IFACE + ".WPS"
- WPAS_DBUS_NETWORK = "fi.w1.wpa_supplicant1.Network"
- WPAS_DBUS_BSS = "fi.w1.wpa_supplicant1.BSS"
- WPAS_DBUS_IFACE_P2PDEVICE = WPAS_DBUS_IFACE + ".P2PDevice"
- WPAS_DBUS_P2P_PEER = "fi.w1.wpa_supplicant1.Peer"
- WPAS_DBUS_GROUP = "fi.w1.wpa_supplicant1.Group"
- WPAS_DBUS_PERSISTENT_GROUP = "fi.w1.wpa_supplicant1.PersistentGroup"
- def prepare_dbus(dev):
- if not dbus_imported:
- logger.info("No dbus module available")
- raise HwsimSkip("No dbus module available")
- try:
- from dbus.mainloop.glib import DBusGMainLoop
- dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
- bus = dbus.SystemBus()
- wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_PATH)
- wpas = dbus.Interface(wpas_obj, WPAS_DBUS_SERVICE)
- path = wpas.GetInterface(dev.ifname)
- if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- return (bus,wpas_obj,path,if_obj)
- except Exception, e:
- raise HwsimSkip("Could not connect to D-Bus: %s" % e)
- class TestDbus(object):
- def __init__(self, bus):
- self.loop = gobject.MainLoop()
- self.signals = []
- self.bus = bus
- def __exit__(self, type, value, traceback):
- for s in self.signals:
- s.remove()
- def add_signal(self, handler, interface, name, byte_arrays=False):
- s = self.bus.add_signal_receiver(handler, dbus_interface=interface,
- signal_name=name,
- byte_arrays=byte_arrays)
- self.signals.append(s)
- def timeout(self, *args):
- logger.debug("timeout")
- self.loop.quit()
- return False
- class alloc_fail_dbus(object):
- def __init__(self, dev, count, funcs, operation="Operation",
- expected="NoMemory"):
- self._dev = dev
- self._count = count
- self._funcs = funcs
- self._operation = operation
- self._expected = expected
- def __enter__(self):
- cmd = "TEST_ALLOC_FAIL %d:%s" % (self._count, self._funcs)
- if "OK" not in self._dev.request(cmd):
- raise HwsimSkip("TEST_ALLOC_FAIL not supported")
- def __exit__(self, type, value, traceback):
- if type is None:
- raise Exception("%s succeeded during out-of-memory" % self._operation)
- if type == dbus.exceptions.DBusException and self._expected in str(value):
- return True
- if self._dev.request("GET_ALLOC_FAIL") != "0:%s" % self._funcs:
- raise Exception("%s did not trigger allocation failure" % self._operation)
- return False
- def start_ap(ap, ssid="test-wps",
- ap_uuid="27ea801a-9e5c-4e73-bd82-f89cbcd10d7e"):
- params = { "ssid": ssid, "eap_server": "1", "wps_state": "2",
- "wpa_passphrase": "12345678", "wpa": "2",
- "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP",
- "ap_pin": "12345670", "uuid": ap_uuid}
- return hostapd.add_ap(ap, params)
- def test_dbus_getall(dev, apdev):
- """D-Bus GetAll"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- props = wpas_obj.GetAll(WPAS_DBUS_SERVICE,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(fi.w1.wpa.supplicant1, /fi/w1/wpa_supplicant1) ==> " + str(props))
- props = if_obj.GetAll(WPAS_DBUS_IFACE,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_IFACE, path, str(props)))
- props = if_obj.GetAll(WPAS_DBUS_IFACE_WPS,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_IFACE_WPS, path, str(props)))
- res = if_obj.Get(WPAS_DBUS_IFACE, 'BSSs',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 0:
- raise Exception("Unexpected BSSs entry: " + str(res))
- res = if_obj.Get(WPAS_DBUS_IFACE, 'Networks',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 0:
- raise Exception("Unexpected Networks entry: " + str(res))
- hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq=2412)
- id = dev[0].add_network()
- dev[0].set_network(id, "disabled", "0")
- dev[0].set_network_quoted(id, "ssid", "test")
- res = if_obj.Get(WPAS_DBUS_IFACE, 'BSSs',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 1:
- raise Exception("Missing BSSs entry: " + str(res))
- bss_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0])
- props = bss_obj.GetAll(WPAS_DBUS_BSS, dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_BSS, res[0], str(props)))
- bssid_str = ''
- for item in props['BSSID']:
- if len(bssid_str) > 0:
- bssid_str += ':'
- bssid_str += '%02x' % item
- if bssid_str != bssid:
- raise Exception("Unexpected BSSID in BSSs entry")
- res = if_obj.Get(WPAS_DBUS_IFACE, 'Networks',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 1:
- raise Exception("Missing Networks entry: " + str(res))
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0])
- props = net_obj.GetAll(WPAS_DBUS_NETWORK,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_NETWORK, res[0], str(props)))
- ssid = props['Properties']['ssid']
- if ssid != '"test"':
- raise Exception("Unexpected SSID in network entry")
- def test_dbus_getall_oom(dev, apdev):
- """D-Bus GetAll wpa_config_get_all() OOM"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- id = dev[0].add_network()
- dev[0].set_network(id, "disabled", "0")
- dev[0].set_network_quoted(id, "ssid", "test")
- res = if_obj.Get(WPAS_DBUS_IFACE, 'Networks',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 1:
- raise Exception("Missing Networks entry: " + str(res))
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0])
- for i in range(1, 50):
- with alloc_fail(dev[0], i, "wpa_config_get_all"):
- try:
- props = net_obj.GetAll(WPAS_DBUS_NETWORK,
- dbus_interface=dbus.PROPERTIES_IFACE)
- except dbus.exceptions.DBusException, e:
- pass
- def dbus_get(dbus, wpas_obj, prop, expect=None, byte_arrays=False):
- val = wpas_obj.Get(WPAS_DBUS_SERVICE, prop,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=byte_arrays)
- if expect is not None and val != expect:
- raise Exception("Unexpected %s: %s (expected: %s)" %
- (prop, str(val), str(expect)))
- return val
- def dbus_set(dbus, wpas_obj, prop, val):
- wpas_obj.Set(WPAS_DBUS_SERVICE, prop, val,
- dbus_interface=dbus.PROPERTIES_IFACE)
- def test_dbus_properties(dev, apdev):
- """D-Bus Get/Set fi.w1.wpa_supplicant1 properties"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- dbus_get(dbus, wpas_obj, "DebugLevel", expect="msgdump")
- dbus_set(dbus, wpas_obj, "DebugLevel", "debug")
- dbus_get(dbus, wpas_obj, "DebugLevel", expect="debug")
- for (val,err) in [ (3, "Error.Failed: wrong property type"),
- ("foo", "Error.Failed: wrong debug level value") ]:
- try:
- dbus_set(dbus, wpas_obj, "DebugLevel", val)
- raise Exception("Invalid DebugLevel value accepted: " + str(val))
- except dbus.exceptions.DBusException, e:
- if err not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- dbus_set(dbus, wpas_obj, "DebugLevel", "msgdump")
- dbus_get(dbus, wpas_obj, "DebugLevel", expect="msgdump")
- dbus_get(dbus, wpas_obj, "DebugTimestamp", expect=True)
- dbus_set(dbus, wpas_obj, "DebugTimestamp", False)
- dbus_get(dbus, wpas_obj, "DebugTimestamp", expect=False)
- try:
- dbus_set(dbus, wpas_obj, "DebugTimestamp", "foo")
- raise Exception("Invalid DebugTimestamp value accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- dbus_set(dbus, wpas_obj, "DebugTimestamp", True)
- dbus_get(dbus, wpas_obj, "DebugTimestamp", expect=True)
- dbus_get(dbus, wpas_obj, "DebugShowKeys", expect=True)
- dbus_set(dbus, wpas_obj, "DebugShowKeys", False)
- dbus_get(dbus, wpas_obj, "DebugShowKeys", expect=False)
- try:
- dbus_set(dbus, wpas_obj, "DebugShowKeys", "foo")
- raise Exception("Invalid DebugShowKeys value accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- dbus_set(dbus, wpas_obj, "DebugShowKeys", True)
- dbus_get(dbus, wpas_obj, "DebugShowKeys", expect=True)
- res = dbus_get(dbus, wpas_obj, "Interfaces")
- if len(res) != 1:
- raise Exception("Unexpected Interfaces value: " + str(res))
- res = dbus_get(dbus, wpas_obj, "EapMethods")
- if len(res) < 5 or "TTLS" not in res:
- raise Exception("Unexpected EapMethods value: " + str(res))
- res = dbus_get(dbus, wpas_obj, "Capabilities")
- if len(res) < 2 or "p2p" not in res:
- raise Exception("Unexpected Capabilities value: " + str(res))
- dbus_get(dbus, wpas_obj, "WFDIEs", byte_arrays=True)
- val = binascii.unhexlify("010006020304050608")
- dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(val))
- res = dbus_get(dbus, wpas_obj, "WFDIEs", byte_arrays=True)
- if val != res:
- raise Exception("WFDIEs value changed")
- try:
- dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray('\x00'))
- raise Exception("Invalid WFDIEs value accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(''))
- dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(val))
- dbus_set(dbus, wpas_obj, "WFDIEs", dbus.ByteArray(''))
- res = dbus_get(dbus, wpas_obj, "WFDIEs", byte_arrays=True)
- if len(res) != 0:
- raise Exception("WFDIEs not cleared properly")
- res = dbus_get(dbus, wpas_obj, "EapMethods")
- try:
- dbus_set(dbus, wpas_obj, "EapMethods", res)
- raise Exception("Invalid Set accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: Property is read-only" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- try:
- wpas_obj.SetFoo(WPAS_DBUS_SERVICE, "DebugShowKeys", True,
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Unknown method accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownMethod" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- try:
- wpas_obj.Get("foo", "DebugShowKeys",
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Get accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: No such property" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- test_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_PATH,
- introspect=False)
- try:
- test_obj.Get(123, "DebugShowKeys",
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Get accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: Invalid arguments" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- try:
- test_obj.Get(WPAS_DBUS_SERVICE, 123,
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Get accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: Invalid arguments" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- try:
- wpas_obj.Set(WPAS_DBUS_SERVICE, "WFDIEs",
- dbus.ByteArray('', variant_level=2),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: invalid message format" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- def test_dbus_set_global_properties(dev, apdev):
- """D-Bus Get/Set fi.w1.wpa_supplicant1 interface global properties"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- props = [ ('Okc', '0', '1'), ('ModelName', '', 'blahblahblah') ]
- for p in props:
- res = if_obj.Get(WPAS_DBUS_IFACE, p[0],
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != p[1]:
- raise Exception("Unexpected " + p[0] + " value: " + str(res))
- if_obj.Set(WPAS_DBUS_IFACE, p[0], p[2],
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, p[0],
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != p[2]:
- raise Exception("Unexpected " + p[0] + " value after set: " + str(res))
- def test_dbus_invalid_method(dev, apdev):
- """D-Bus invalid method"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- try:
- wps.Foo()
- raise Exception("Unknown method accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownMethod" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- test_obj = bus.get_object(WPAS_DBUS_SERVICE, path, introspect=False)
- test_wps = dbus.Interface(test_obj, WPAS_DBUS_IFACE_WPS)
- try:
- test_wps.Start(123)
- raise Exception("WPS.Start with incorrect signature accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs: Invalid arg" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- def test_dbus_get_set_wps(dev, apdev):
- """D-Bus Get/Set for WPS properties"""
- try:
- _test_dbus_get_set_wps(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- dev[0].request("SET config_methods display keypad virtual_display nfc_interface p2ps")
- def _test_dbus_get_set_wps(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- if_obj.Get(WPAS_DBUS_IFACE_WPS, "ConfigMethods",
- dbus_interface=dbus.PROPERTIES_IFACE)
- val = "display keypad virtual_display nfc_interface"
- dev[0].request("SET config_methods " + val)
- config = if_obj.Get(WPAS_DBUS_IFACE_WPS, "ConfigMethods",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if config != val:
- raise Exception("Unexpected Get(ConfigMethods) result: " + config)
- val2 = "push_button display"
- if_obj.Set(WPAS_DBUS_IFACE_WPS, "ConfigMethods", val2,
- dbus_interface=dbus.PROPERTIES_IFACE)
- config = if_obj.Get(WPAS_DBUS_IFACE_WPS, "ConfigMethods",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if config != val2:
- raise Exception("Unexpected Get(ConfigMethods) result after Set: " + config)
- dev[0].request("SET config_methods " + val)
- for i in range(3):
- dev[0].request("SET wps_cred_processing " + str(i))
- val = if_obj.Get(WPAS_DBUS_IFACE_WPS, "ProcessCredentials",
- dbus_interface=dbus.PROPERTIES_IFACE)
- expected_val = False if i == 1 else True
- if val != expected_val:
- raise Exception("Unexpected Get(ProcessCredentials) result({}): {}".format(i, val))
- class TestDbusGetSet(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.signal_received = False
- self.signal_received_deprecated = False
- self.sets_done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_sets)
- gobject.timeout_add(1000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE_WPS,
- "PropertiesChanged")
- self.add_signal(self.propertiesChanged2, dbus.PROPERTIES_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("PropertiesChanged: " + str(properties))
- if properties.has_key("ProcessCredentials"):
- self.signal_received_deprecated = True
- if self.sets_done and self.signal_received:
- self.loop.quit()
- def propertiesChanged2(self, interface_name, changed_properties,
- invalidated_properties):
- logger.debug("propertiesChanged2: interface_name=%s changed_properties=%s invalidated_properties=%s" % (interface_name, str(changed_properties), str(invalidated_properties)))
- if interface_name != WPAS_DBUS_IFACE_WPS:
- return
- if changed_properties.has_key("ProcessCredentials"):
- self.signal_received = True
- if self.sets_done and self.signal_received_deprecated:
- self.loop.quit()
- def run_sets(self, *args):
- logger.debug("run_sets")
- if_obj.Set(WPAS_DBUS_IFACE_WPS, "ProcessCredentials",
- dbus.Boolean(1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- if if_obj.Get(WPAS_DBUS_IFACE_WPS, "ProcessCredentials",
- dbus_interface=dbus.PROPERTIES_IFACE) != True:
- raise Exception("Unexpected Get(ProcessCredentials) result after Set")
- if_obj.Set(WPAS_DBUS_IFACE_WPS, "ProcessCredentials",
- dbus.Boolean(0),
- dbus_interface=dbus.PROPERTIES_IFACE)
- if if_obj.Get(WPAS_DBUS_IFACE_WPS, "ProcessCredentials",
- dbus_interface=dbus.PROPERTIES_IFACE) != False:
- raise Exception("Unexpected Get(ProcessCredentials) result after Set")
- self.dbus_sets_done = True
- return False
- def success(self):
- return self.signal_received and self.signal_received_deprecated
- with TestDbusGetSet(bus) as t:
- if not t.success():
- raise Exception("No signal received for ProcessCredentials change")
- def test_dbus_wps_invalid(dev, apdev):
- """D-Bus invaldi WPS operation"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- failures = [ {'Role': 'foo', 'Type': 'pbc'},
- {'Role': 123, 'Type': 'pbc'},
- {'Type': 'pbc'},
- {'Role': 'enrollee'},
- {'Role': 'registrar'},
- {'Role': 'enrollee', 'Type': 123},
- {'Role': 'enrollee', 'Type': 'foo'},
- {'Role': 'enrollee', 'Type': 'pbc',
- 'Bssid': '02:33:44:55:66:77'},
- {'Role': 'enrollee', 'Type': 'pin', 'Pin': 123},
- {'Role': 'enrollee', 'Type': 'pbc',
- 'Bssid': dbus.ByteArray('12345')},
- {'Role': 'enrollee', 'Type': 'pbc',
- 'P2PDeviceAddress': 12345},
- {'Role': 'enrollee', 'Type': 'pbc',
- 'P2PDeviceAddress': dbus.ByteArray('12345')},
- {'Role': 'enrollee', 'Type': 'pbc', 'Foo': 'bar'} ]
- for args in failures:
- try:
- wps.Start(args)
- raise Exception("Invalid WPS.Start() arguments accepted: " + str(args))
- except dbus.exceptions.DBusException, e:
- if not str(e).startswith("fi.w1.wpa_supplicant1.InvalidArgs"):
- raise Exception("Unexpected error message: " + str(e))
- def test_dbus_wps_oom(dev, apdev):
- """D-Bus WPS operation (OOM)"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- with alloc_fail_dbus(dev[0], 1, "=wpas_dbus_getter_state", "Get"):
- if_obj.Get(WPAS_DBUS_IFACE, "State",
- dbus_interface=dbus.PROPERTIES_IFACE)
- hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq=2412)
- time.sleep(0.05)
- for i in range(1, 3):
- with alloc_fail_dbus(dev[0], i, "=wpas_dbus_getter_bsss", "Get"):
- if_obj.Get(WPAS_DBUS_IFACE, "BSSs",
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, 'BSSs',
- dbus_interface=dbus.PROPERTIES_IFACE)
- bss_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0])
- with alloc_fail_dbus(dev[0], 1, "=wpas_dbus_getter_bss_rates", "Get"):
- bss_obj.Get(WPAS_DBUS_BSS, "Rates",
- dbus_interface=dbus.PROPERTIES_IFACE)
- with alloc_fail(dev[0], 1,
- "wpa_bss_get_bit_rates;wpas_dbus_getter_bss_rates"):
- try:
- bss_obj.Get(WPAS_DBUS_BSS, "Rates",
- dbus_interface=dbus.PROPERTIES_IFACE)
- except dbus.exceptions.DBusException, e:
- pass
- id = dev[0].add_network()
- dev[0].set_network(id, "disabled", "0")
- dev[0].set_network_quoted(id, "ssid", "test")
- for i in range(1, 3):
- with alloc_fail_dbus(dev[0], i, "=wpas_dbus_getter_networks", "Get"):
- if_obj.Get(WPAS_DBUS_IFACE, "Networks",
- dbus_interface=dbus.PROPERTIES_IFACE)
- with alloc_fail_dbus(dev[0], 1, "wpas_dbus_getter_interfaces", "Get"):
- dbus_get(dbus, wpas_obj, "Interfaces")
- for i in range(1, 6):
- with alloc_fail_dbus(dev[0], i, "=eap_get_names_as_string_array;wpas_dbus_getter_eap_methods", "Get"):
- dbus_get(dbus, wpas_obj, "EapMethods")
- with alloc_fail_dbus(dev[0], 1, "wpas_dbus_setter_config_methods", "Set",
- expected="Error.Failed: Failed to set property"):
- val2 = "push_button display"
- if_obj.Set(WPAS_DBUS_IFACE_WPS, "ConfigMethods", val2,
- dbus_interface=dbus.PROPERTIES_IFACE)
- with alloc_fail_dbus(dev[0], 1, "=wpa_config_add_network;wpas_dbus_handler_wps_start",
- "WPS.Start",
- expected="UnknownError: WPS start failed"):
- wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670'})
- def test_dbus_wps_pbc(dev, apdev):
- """D-Bus WPS/PBC operation and signals"""
- try:
- _test_dbus_wps_pbc(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- def _test_dbus_wps_pbc(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- hapd.request("WPS_PBC")
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- dev[0].request("SET wps_cred_processing 2")
- res = if_obj.Get(WPAS_DBUS_IFACE, 'BSSs',
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 1:
- raise Exception("Missing BSSs entry: " + str(res))
- bss_obj = bus.get_object(WPAS_DBUS_SERVICE, res[0])
- props = bss_obj.GetAll(WPAS_DBUS_BSS, dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("GetAll(%s, %s): %s" % (WPAS_DBUS_BSS, res[0], str(props)))
- if 'WPS' not in props:
- raise Exception("No WPS information in the BSS entry")
- if 'Type' not in props['WPS']:
- raise Exception("No Type field in the WPS dictionary")
- if props['WPS']['Type'] != 'pbc':
- raise Exception("Unexpected WPS Type: " + props['WPS']['Type'])
- class TestDbusWps(TestDbus):
- def __init__(self, bus, wps):
- TestDbus.__init__(self, bus)
- self.success_seen = False
- self.credentials_received = False
- self.wps = wps
- def __enter__(self):
- gobject.timeout_add(1, self.start_pbc)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.add_signal(self.credentials, WPAS_DBUS_IFACE_WPS,
- "Credentials")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- if name == "success":
- self.success_seen = True
- if self.credentials_received:
- self.loop.quit()
- def credentials(self, args):
- logger.debug("credentials: " + str(args))
- self.credentials_received = True
- if self.success_seen:
- self.loop.quit()
- def start_pbc(self, *args):
- logger.debug("start_pbc")
- self.wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
- return False
- def success(self):
- return self.success_seen and self.credentials_received
- with TestDbusWps(bus, wps) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].wait_connected(timeout=10)
- dev[0].request("DISCONNECT")
- hapd.disable()
- dev[0].flush_scan_cache()
- def test_dbus_wps_pbc_overlap(dev, apdev):
- """D-Bus WPS/PBC operation and signal for PBC overlap"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- hapd2 = start_ap(apdev[1], ssid="test-wps2",
- ap_uuid="27ea801a-9e5c-4e73-bd82-f89cbcd10d7f")
- hapd.request("WPS_PBC")
- hapd2.request("WPS_PBC")
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- bssid2 = apdev[1]['bssid']
- dev[0].scan_for_bss(bssid2, freq="2412")
- class TestDbusWps(TestDbus):
- def __init__(self, bus, wps):
- TestDbus.__init__(self, bus)
- self.overlap_seen = False
- self.wps = wps
- def __enter__(self):
- gobject.timeout_add(1, self.start_pbc)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- if name == "pbc-overlap":
- self.overlap_seen = True
- self.loop.quit()
- def start_pbc(self, *args):
- logger.debug("start_pbc")
- self.wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
- return False
- def success(self):
- return self.overlap_seen
- with TestDbusWps(bus, wps) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].request("WPS_CANCEL")
- dev[0].request("DISCONNECT")
- hapd.disable()
- dev[0].flush_scan_cache()
- def test_dbus_wps_pin(dev, apdev):
- """D-Bus WPS/PIN operation and signals"""
- try:
- _test_dbus_wps_pin(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- def _test_dbus_wps_pin(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- hapd.request("WPS_PIN any 12345670")
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- dev[0].request("SET wps_cred_processing 2")
- class TestDbusWps(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.success_seen = False
- self.credentials_received = False
- def __enter__(self):
- gobject.timeout_add(1, self.start_pin)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.add_signal(self.credentials, WPAS_DBUS_IFACE_WPS,
- "Credentials")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- if name == "success":
- self.success_seen = True
- if self.credentials_received:
- self.loop.quit()
- def credentials(self, args):
- logger.debug("credentials: " + str(args))
- self.credentials_received = True
- if self.success_seen:
- self.loop.quit()
- def start_pin(self, *args):
- logger.debug("start_pin")
- bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
- wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
- 'Bssid': bssid_ay})
- return False
- def success(self):
- return self.success_seen and self.credentials_received
- with TestDbusWps(bus) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].wait_connected(timeout=10)
- def test_dbus_wps_pin2(dev, apdev):
- """D-Bus WPS/PIN operation and signals (PIN from wpa_supplicant)"""
- try:
- _test_dbus_wps_pin2(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- def _test_dbus_wps_pin2(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- dev[0].request("SET wps_cred_processing 2")
- class TestDbusWps(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.success_seen = False
- self.failed = False
- def __enter__(self):
- gobject.timeout_add(1, self.start_pin)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.add_signal(self.credentials, WPAS_DBUS_IFACE_WPS,
- "Credentials")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- if name == "success":
- self.success_seen = True
- if self.credentials_received:
- self.loop.quit()
- def credentials(self, args):
- logger.debug("credentials: " + str(args))
- self.credentials_received = True
- if self.success_seen:
- self.loop.quit()
- def start_pin(self, *args):
- logger.debug("start_pin")
- bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
- res = wps.Start({'Role': 'enrollee', 'Type': 'pin',
- 'Bssid': bssid_ay})
- pin = res['Pin']
- h = hostapd.Hostapd(apdev[0]['ifname'])
- h.request("WPS_PIN any " + pin)
- return False
- def success(self):
- return self.success_seen and self.credentials_received
- with TestDbusWps(bus) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].wait_connected(timeout=10)
- def test_dbus_wps_pin_m2d(dev, apdev):
- """D-Bus WPS/PIN operation and signals with M2D"""
- try:
- _test_dbus_wps_pin_m2d(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- def _test_dbus_wps_pin_m2d(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- dev[0].request("SET wps_cred_processing 2")
- class TestDbusWps(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.success_seen = False
- self.credentials_received = False
- def __enter__(self):
- gobject.timeout_add(1, self.start_pin)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.add_signal(self.credentials, WPAS_DBUS_IFACE_WPS,
- "Credentials")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- if name == "success":
- self.success_seen = True
- if self.credentials_received:
- self.loop.quit()
- elif name == "m2d":
- h = hostapd.Hostapd(apdev[0]['ifname'])
- h.request("WPS_PIN any 12345670")
- def credentials(self, args):
- logger.debug("credentials: " + str(args))
- self.credentials_received = True
- if self.success_seen:
- self.loop.quit()
- def start_pin(self, *args):
- logger.debug("start_pin")
- bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
- wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
- 'Bssid': bssid_ay})
- return False
- def success(self):
- return self.success_seen and self.credentials_received
- with TestDbusWps(bus) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].wait_connected(timeout=10)
- def test_dbus_wps_reg(dev, apdev):
- """D-Bus WPS/Registrar operation and signals"""
- try:
- _test_dbus_wps_reg(dev, apdev)
- finally:
- dev[0].request("SET wps_cred_processing 0")
- def _test_dbus_wps_reg(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- hapd.request("WPS_PIN any 12345670")
- bssid = apdev[0]['bssid']
- dev[0].scan_for_bss(bssid, freq="2412")
- dev[0].request("SET wps_cred_processing 2")
- class TestDbusWps(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.credentials_received = False
- def __enter__(self):
- gobject.timeout_add(100, self.start_reg)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.wpsEvent, WPAS_DBUS_IFACE_WPS, "Event")
- self.add_signal(self.credentials, WPAS_DBUS_IFACE_WPS,
- "Credentials")
- self.loop.run()
- return self
- def wpsEvent(self, name, args):
- logger.debug("wpsEvent: %s args='%s'" % (name, str(args)))
- def credentials(self, args):
- logger.debug("credentials: " + str(args))
- self.credentials_received = True
- self.loop.quit()
- def start_reg(self, *args):
- logger.debug("start_reg")
- bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
- wps.Start({'Role': 'registrar', 'Type': 'pin',
- 'Pin': '12345670', 'Bssid': bssid_ay})
- return False
- def success(self):
- return self.credentials_received
- with TestDbusWps(bus) as t:
- if not t.success():
- raise Exception("Failure in D-Bus operations")
- dev[0].wait_connected(timeout=10)
- def test_dbus_wps_cancel(dev, apdev):
- """D-Bus WPS Cancel operation"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wps = dbus.Interface(if_obj, WPAS_DBUS_IFACE_WPS)
- hapd = start_ap(apdev[0])
- bssid = apdev[0]['bssid']
- wps.Cancel()
- dev[0].scan_for_bss(bssid, freq="2412")
- bssid_ay = dbus.ByteArray(bssid.replace(':','').decode('hex'))
- wps.Start({'Role': 'enrollee', 'Type': 'pin', 'Pin': '12345670',
- 'Bssid': bssid_ay})
- wps.Cancel()
- dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 1)
- def test_dbus_scan_invalid(dev, apdev):
- """D-Bus invalid scan method"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- tests = [ ({}, "InvalidArgs"),
- ({'Type': 123}, "InvalidArgs"),
- ({'Type': 'foo'}, "InvalidArgs"),
- ({'Type': 'active', 'Foo': 'bar'}, "InvalidArgs"),
- ({'Type': 'active', 'SSIDs': 'foo'}, "InvalidArgs"),
- ({'Type': 'active', 'SSIDs': ['foo']}, "InvalidArgs"),
- ({'Type': 'active',
- 'SSIDs': [ dbus.ByteArray("1"), dbus.ByteArray("2"),
- dbus.ByteArray("3"), dbus.ByteArray("4"),
- dbus.ByteArray("5"), dbus.ByteArray("6"),
- dbus.ByteArray("7"), dbus.ByteArray("8"),
- dbus.ByteArray("9"), dbus.ByteArray("10"),
- dbus.ByteArray("11"), dbus.ByteArray("12"),
- dbus.ByteArray("13"), dbus.ByteArray("14"),
- dbus.ByteArray("15"), dbus.ByteArray("16"),
- dbus.ByteArray("17") ]},
- "InvalidArgs"),
- ({'Type': 'active',
- 'SSIDs': [ dbus.ByteArray("1234567890abcdef1234567890abcdef1") ]},
- "InvalidArgs"),
- ({'Type': 'active', 'IEs': 'foo'}, "InvalidArgs"),
- ({'Type': 'active', 'IEs': ['foo']}, "InvalidArgs"),
- ({'Type': 'active', 'Channels': 2412 }, "InvalidArgs"),
- ({'Type': 'active', 'Channels': [ 2412 ] }, "InvalidArgs"),
- ({'Type': 'active',
- 'Channels': [ (dbus.Int32(2412), dbus.UInt32(20)) ] },
- "InvalidArgs"),
- ({'Type': 'active',
- 'Channels': [ (dbus.UInt32(2412), dbus.Int32(20)) ] },
- "InvalidArgs"),
- ({'Type': 'active', 'AllowRoam': "yes" }, "InvalidArgs"),
- ({'Type': 'passive', 'IEs': [ dbus.ByteArray("\xdd\x00") ]},
- "InvalidArgs"),
- ({'Type': 'passive', 'SSIDs': [ dbus.ByteArray("foo") ]},
- "InvalidArgs")]
- for (t,err) in tests:
- try:
- iface.Scan(t)
- raise Exception("Invalid Scan() arguments accepted: " + str(t))
- except dbus.exceptions.DBusException, e:
- if err not in str(e):
- raise Exception("Unexpected error message for invalid Scan(%s): %s" % (str(t), str(e)))
- def test_dbus_scan_oom(dev, apdev):
- """D-Bus scan method and OOM"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- with alloc_fail_dbus(dev[0], 1,
- "wpa_scan_clone_params;wpas_dbus_handler_scan",
- "Scan", expected="ScanError: Scan request rejected"):
- iface.Scan({ 'Type': 'passive',
- 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] })
- with alloc_fail_dbus(dev[0], 1,
- "=wpas_dbus_get_scan_channels;wpas_dbus_handler_scan",
- "Scan"):
- iface.Scan({ 'Type': 'passive',
- 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] })
- with alloc_fail_dbus(dev[0], 1,
- "=wpas_dbus_get_scan_ies;wpas_dbus_handler_scan",
- "Scan"):
- iface.Scan({ 'Type': 'active',
- 'IEs': [ dbus.ByteArray("\xdd\x00") ],
- 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] })
- with alloc_fail_dbus(dev[0], 1,
- "=wpas_dbus_get_scan_ssids;wpas_dbus_handler_scan",
- "Scan"):
- iface.Scan({ 'Type': 'active',
- 'SSIDs': [ dbus.ByteArray("open"),
- dbus.ByteArray() ],
- 'Channels': [ (dbus.UInt32(2412), dbus.UInt32(20)) ] })
- def test_dbus_scan(dev, apdev):
- """D-Bus scan and related signals"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
- class TestDbusScan(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.scan_completed = 0
- self.bss_added = False
- self.fail_reason = None
- def __enter__(self):
- gobject.timeout_add(1, self.run_scan)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.scanDone, WPAS_DBUS_IFACE, "ScanDone")
- self.add_signal(self.bssAdded, WPAS_DBUS_IFACE, "BSSAdded")
- self.add_signal(self.bssRemoved, WPAS_DBUS_IFACE, "BSSRemoved")
- self.loop.run()
- return self
- def scanDone(self, success):
- logger.debug("scanDone: success=%s" % success)
- self.scan_completed += 1
- if self.scan_completed == 1:
- iface.Scan({'Type': 'passive',
- 'AllowRoam': True,
- 'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]})
- elif self.scan_completed == 2:
- iface.Scan({'Type': 'passive',
- 'AllowRoam': False})
- elif self.bss_added and self.scan_completed == 3:
- self.loop.quit()
- def bssAdded(self, bss, properties):
- logger.debug("bssAdded: %s" % bss)
- logger.debug(str(properties))
- if 'WPS' in properties:
- if 'Type' in properties['WPS']:
- self.fail_reason = "Unexpected WPS dictionary entry in non-WPS BSS"
- self.loop.quit()
- self.bss_added = True
- if self.scan_completed == 3:
- self.loop.quit()
- def bssRemoved(self, bss):
- logger.debug("bssRemoved: %s" % bss)
- def run_scan(self, *args):
- logger.debug("run_scan")
- iface.Scan({'Type': 'active',
- 'SSIDs': [ dbus.ByteArray("open"),
- dbus.ByteArray() ],
- 'IEs': [ dbus.ByteArray("\xdd\x00"),
- dbus.ByteArray() ],
- 'AllowRoam': False,
- 'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]})
- return False
- def success(self):
- return self.scan_completed == 3 and self.bss_added
- with TestDbusScan(bus) as t:
- if t.fail_reason:
- raise Exception(t.fail_reason)
- if not t.success():
- raise Exception("Expected signals not seen")
- res = if_obj.Get(WPAS_DBUS_IFACE, "BSSs",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) < 1:
- raise Exception("Scan result not in BSSs property")
- iface.FlushBSS(0)
- res = if_obj.Get(WPAS_DBUS_IFACE, "BSSs",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 0:
- raise Exception("FlushBSS() did not remove scan results from BSSs property")
- iface.FlushBSS(1)
- def test_dbus_scan_busy(dev, apdev):
- """D-Bus scan trigger rejection when busy with previous scan"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- if "OK" not in dev[0].request("SCAN freq=2412-2462"):
- raise Exception("Failed to start scan")
- ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], 15)
- if ev is None:
- raise Exception("Scan start timed out")
- try:
- iface.Scan({'Type': 'active', 'AllowRoam': False})
- raise Exception("Scan() accepted when busy")
- except dbus.exceptions.DBusException, e:
- if "ScanError: Scan request reject" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
- if ev is None:
- raise Exception("Scan timed out")
- def test_dbus_connect(dev, apdev):
- """D-Bus AddNetwork and connect"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "test-wpa2-psk"
- passphrase = 'qwertyuiop'
- params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.network_added = False
- self.network_selected = False
- self.network_removed = False
- self.state = 0
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.networkAdded, WPAS_DBUS_IFACE, "NetworkAdded")
- self.add_signal(self.networkRemoved, WPAS_DBUS_IFACE,
- "NetworkRemoved")
- self.add_signal(self.networkSelected, WPAS_DBUS_IFACE,
- "NetworkSelected")
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def networkAdded(self, network, properties):
- logger.debug("networkAdded: %s" % str(network))
- logger.debug(str(properties))
- self.network_added = True
- def networkRemoved(self, network):
- logger.debug("networkRemoved: %s" % str(network))
- self.network_removed = True
- def networkSelected(self, network):
- logger.debug("networkSelected: %s" % str(network))
- self.network_selected = True
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- if self.state == 0:
- self.state = 1
- iface.Disconnect()
- elif self.state == 2:
- self.state = 3
- iface.Disconnect()
- elif self.state == 4:
- self.state = 5
- iface.Reattach()
- elif self.state == 5:
- self.state = 6
- iface.Disconnect()
- elif self.state == 7:
- self.state = 8
- res = iface.SignalPoll()
- logger.debug("SignalPoll: " + str(res))
- if 'frequency' not in res or res['frequency'] != 2412:
- self.state = -1
- logger.info("Unexpected SignalPoll result")
- iface.RemoveNetwork(self.netw)
- if 'State' in properties and properties['State'] == "disconnected":
- if self.state == 1:
- self.state = 2
- iface.SelectNetwork(self.netw)
- elif self.state == 3:
- self.state = 4
- iface.Reassociate()
- elif self.state == 6:
- self.state = 7
- iface.Reconnect()
- elif self.state == 8:
- self.state = 9
- self.loop.quit()
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'WPA-PSK',
- 'psk': passphrase,
- 'scan_freq': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- if not self.network_added or \
- not self.network_removed or \
- not self.network_selected:
- return False
- return self.state == 9
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_connect_psk_mem(dev, apdev):
- """D-Bus AddNetwork and connect with memory-only PSK"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "test-wpa2-psk"
- passphrase = 'qwertyuiop'
- params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.connected = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.add_signal(self.networkRequest, WPAS_DBUS_IFACE,
- "NetworkRequest")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- self.connected = True
- self.loop.quit()
- def networkRequest(self, path, field, txt):
- logger.debug("networkRequest: %s %s %s" % (path, field, txt))
- if field == "PSK_PASSPHRASE":
- iface.NetworkReply(path, field, '"' + passphrase + '"')
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'WPA-PSK',
- 'mem_only_psk': 1,
- 'scan_freq': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- return self.connected
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_connect_oom(dev, apdev):
- """D-Bus AddNetwork and connect when out-of-memory"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- if "OK" not in dev[0].request("TEST_ALLOC_FAIL 0:"):
- raise HwsimSkip("TEST_ALLOC_FAIL not supported in the build")
- ssid = "test-wpa2-psk"
- passphrase = 'qwertyuiop'
- params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.network_added = False
- self.network_selected = False
- self.network_removed = False
- self.state = 0
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(1500, self.timeout)
- self.add_signal(self.networkAdded, WPAS_DBUS_IFACE, "NetworkAdded")
- self.add_signal(self.networkRemoved, WPAS_DBUS_IFACE,
- "NetworkRemoved")
- self.add_signal(self.networkSelected, WPAS_DBUS_IFACE,
- "NetworkSelected")
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def networkAdded(self, network, properties):
- logger.debug("networkAdded: %s" % str(network))
- logger.debug(str(properties))
- self.network_added = True
- def networkRemoved(self, network):
- logger.debug("networkRemoved: %s" % str(network))
- self.network_removed = True
- def networkSelected(self, network):
- logger.debug("networkSelected: %s" % str(network))
- self.network_selected = True
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- if self.state == 0:
- self.state = 1
- iface.Disconnect()
- elif self.state == 2:
- self.state = 3
- iface.Disconnect()
- elif self.state == 4:
- self.state = 5
- iface.Reattach()
- elif self.state == 5:
- self.state = 6
- res = iface.SignalPoll()
- logger.debug("SignalPoll: " + str(res))
- if 'frequency' not in res or res['frequency'] != 2412:
- self.state = -1
- logger.info("Unexpected SignalPoll result")
- iface.RemoveNetwork(self.netw)
- if 'State' in properties and properties['State'] == "disconnected":
- if self.state == 1:
- self.state = 2
- iface.SelectNetwork(self.netw)
- elif self.state == 3:
- self.state = 4
- iface.Reassociate()
- elif self.state == 6:
- self.state = 7
- self.loop.quit()
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'WPA-PSK',
- 'psk': passphrase,
- 'scan_freq': 2412 },
- signature='sv')
- try:
- self.netw = iface.AddNetwork(args)
- except Exception, e:
- logger.info("Exception on AddNetwork: " + str(e))
- self.loop.quit()
- return False
- try:
- iface.SelectNetwork(self.netw)
- except Exception, e:
- logger.info("Exception on SelectNetwork: " + str(e))
- self.loop.quit()
- return False
- def success(self):
- if not self.network_added or \
- not self.network_removed or \
- not self.network_selected:
- return False
- return self.state == 7
- count = 0
- for i in range(1, 1000):
- for j in range(3):
- dev[j].dump_monitor()
- dev[0].request("TEST_ALLOC_FAIL %d:main" % i)
- try:
- with TestDbusConnect(bus) as t:
- if not t.success():
- logger.info("Iteration %d - Expected signals not seen" % i)
- else:
- logger.info("Iteration %d - success" % i)
- state = dev[0].request('GET_ALLOC_FAIL')
- logger.info("GET_ALLOC_FAIL: " + state)
- dev[0].dump_monitor()
- dev[0].request("TEST_ALLOC_FAIL 0:")
- if i < 3:
- raise Exception("Connection succeeded during out-of-memory")
- if not state.startswith('0:'):
- count += 1
- if count == 5:
- break
- except:
- pass
- # Force regulatory update to re-fetch hw capabilities for the following
- # test cases.
- try:
- dev[0].dump_monitor()
- subprocess.call(['iw', 'reg', 'set', 'US'])
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- finally:
- dev[0].dump_monitor()
- subprocess.call(['iw', 'reg', 'set', '00'])
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- def test_dbus_while_not_connected(dev, apdev):
- """D-Bus invalid operations while not connected"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- try:
- iface.Disconnect()
- raise Exception("Disconnect() accepted when not connected")
- except dbus.exceptions.DBusException, e:
- if "NotConnected" not in str(e):
- raise Exception("Unexpected error message for invalid Disconnect: " + str(e))
- try:
- iface.Reattach()
- raise Exception("Reattach() accepted when not connected")
- except dbus.exceptions.DBusException, e:
- if "NotConnected" not in str(e):
- raise Exception("Unexpected error message for invalid Reattach: " + str(e))
- def test_dbus_connect_eap(dev, apdev):
- """D-Bus AddNetwork and connect to EAP network"""
- check_altsubject_match_support(dev[0])
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "ieee8021x-open"
- params = hostapd.radius_params()
- params["ssid"] = ssid
- params["ieee8021x"] = "1"
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.certification_received = False
- self.eap_status = False
- self.state = 0
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.add_signal(self.certification, WPAS_DBUS_IFACE,
- "Certification", byte_arrays=True)
- self.add_signal(self.networkRequest, WPAS_DBUS_IFACE,
- "NetworkRequest")
- self.add_signal(self.eap, WPAS_DBUS_IFACE, "EAP")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- if self.state == 0:
- self.state = 1
- iface.EAPLogoff()
- logger.info("Set dNSName constraint")
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, self.netw)
- args = dbus.Dictionary({ 'altsubject_match':
- self.server_dnsname },
- signature='sv')
- net_obj.Set(WPAS_DBUS_NETWORK, "Properties", args,
- dbus_interface=dbus.PROPERTIES_IFACE)
- elif self.state == 2:
- self.state = 3
- iface.Disconnect()
- logger.info("Set non-matching dNSName constraint")
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, self.netw)
- args = dbus.Dictionary({ 'altsubject_match':
- self.server_dnsname + "FOO" },
- signature='sv')
- net_obj.Set(WPAS_DBUS_NETWORK, "Properties", args,
- dbus_interface=dbus.PROPERTIES_IFACE)
- if 'State' in properties and properties['State'] == "disconnected":
- if self.state == 1:
- self.state = 2
- iface.EAPLogon()
- iface.SelectNetwork(self.netw)
- if self.state == 3:
- self.state = 4
- iface.SelectNetwork(self.netw)
- def certification(self, args):
- logger.debug("certification: %s" % str(args))
- self.certification_received = True
- if args['depth'] == 0:
- # The test server certificate is supposed to have dNSName
- if len(args['altsubject']) < 1:
- raise Exception("Missing dNSName")
- dnsname = args['altsubject'][0]
- if not dnsname.startswith("DNS:"):
- raise Exception("Expected dNSName not found: " + dnsname)
- logger.info("altsubject: " + dnsname)
- self.server_dnsname = dnsname
- def eap(self, status, parameter):
- logger.debug("EAP: status=%s parameter=%s" % (status, parameter))
- if status == 'completion' and parameter == 'success':
- self.eap_status = True
- if self.state == 4 and status == 'remote certificate verification' and parameter == 'AltSubject mismatch':
- self.state = 5
- self.loop.quit()
- def networkRequest(self, path, field, txt):
- logger.debug("networkRequest: %s %s %s" % (path, field, txt))
- if field == "PASSWORD":
- iface.NetworkReply(path, field, "password")
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'IEEE8021X',
- 'eapol_flags': 0,
- 'eap': 'TTLS',
- 'anonymous_identity': 'ttls',
- 'identity': 'pap user',
- 'ca_cert': 'auth_serv/ca.pem',
- 'phase2': 'auth=PAP',
- 'scan_freq': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- if not self.eap_status or not self.certification_received:
- return False
- return self.state == 5
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_network(dev, apdev):
- """D-Bus AddNetwork/RemoveNetwork parameters and error cases"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- args = dbus.Dictionary({ 'ssid': "foo",
- 'key_mgmt': 'WPA-PSK',
- 'psk': "12345678",
- 'identity': dbus.ByteArray([ 1, 2 ]),
- 'priority': dbus.Int32(0),
- 'scan_freq': dbus.UInt32(2412) },
- signature='sv')
- netw = iface.AddNetwork(args)
- id = int(dev[0].list_networks()[0]['id'])
- val = dev[0].get_network(id, "scan_freq")
- if val != "2412":
- raise Exception("Invalid scan_freq value: " + str(val))
- iface.RemoveNetwork(netw)
- args = dbus.Dictionary({ 'ssid': "foo",
- 'key_mgmt': 'NONE',
- 'scan_freq': "2412 2432",
- 'freq_list': "2412 2417 2432" },
- signature='sv')
- netw = iface.AddNetwork(args)
- id = int(dev[0].list_networks()[0]['id'])
- val = dev[0].get_network(id, "scan_freq")
- if val != "2412 2432":
- raise Exception("Invalid scan_freq value (2): " + str(val))
- val = dev[0].get_network(id, "freq_list")
- if val != "2412 2417 2432":
- raise Exception("Invalid freq_list value: " + str(val))
- iface.RemoveNetwork(netw)
- try:
- iface.RemoveNetwork(netw)
- raise Exception("Invalid RemoveNetwork() accepted")
- except dbus.exceptions.DBusException, e:
- if "NetworkUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveNetwork: " + str(e))
- try:
- iface.SelectNetwork(netw)
- raise Exception("Invalid SelectNetwork() accepted")
- except dbus.exceptions.DBusException, e:
- if "NetworkUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveNetwork: " + str(e))
- args = dbus.Dictionary({ 'ssid': "foo1", 'key_mgmt': 'NONE',
- 'identity': "testuser", 'scan_freq': '2412' },
- signature='sv')
- netw1 = iface.AddNetwork(args)
- args = dbus.Dictionary({ 'ssid': "foo2", 'key_mgmt': 'NONE' },
- signature='sv')
- netw2 = iface.AddNetwork(args)
- res = if_obj.Get(WPAS_DBUS_IFACE, "Networks",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 2:
- raise Exception("Unexpected number of networks")
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, netw1)
- res = net_obj.Get(WPAS_DBUS_NETWORK, "Enabled",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != False:
- raise Exception("Added network was unexpectedly enabled by default")
- net_obj.Set(WPAS_DBUS_NETWORK, "Enabled", dbus.Boolean(True),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = net_obj.Get(WPAS_DBUS_NETWORK, "Enabled",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != True:
- raise Exception("Set(Enabled,True) did not seem to change property value")
- net_obj.Set(WPAS_DBUS_NETWORK, "Enabled", dbus.Boolean(False),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = net_obj.Get(WPAS_DBUS_NETWORK, "Enabled",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != False:
- raise Exception("Set(Enabled,False) did not seem to change property value")
- try:
- net_obj.Set(WPAS_DBUS_NETWORK, "Enabled", dbus.UInt32(1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(Enabled,1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(Enabled,1): " + str(e))
- args = dbus.Dictionary({ 'ssid': "foo1new" }, signature='sv')
- net_obj.Set(WPAS_DBUS_NETWORK, "Properties", args,
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = net_obj.Get(WPAS_DBUS_NETWORK, "Properties",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res['ssid'] != '"foo1new"':
- raise Exception("Set(Properties) failed to update ssid")
- if res['identity'] != '"testuser"':
- raise Exception("Set(Properties) unexpectedly changed unrelated parameter")
- iface.RemoveAllNetworks()
- res = if_obj.Get(WPAS_DBUS_IFACE, "Networks",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != 0:
- raise Exception("Unexpected number of networks")
- iface.RemoveAllNetworks()
- tests = [ dbus.Dictionary({ 'psk': "1234567" }, signature='sv'),
- dbus.Dictionary({ 'identity': dbus.ByteArray() },
- signature='sv'),
- dbus.Dictionary({ 'identity': dbus.Byte(1) }, signature='sv'),
- dbus.Dictionary({ 'identity': "" }, signature='sv') ]
- for args in tests:
- try:
- iface.AddNetwork(args)
- raise Exception("Invalid AddNetwork args accepted: " + str(args))
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid AddNetwork: " + str(e))
- def test_dbus_network_oom(dev, apdev):
- """D-Bus AddNetwork/RemoveNetwork parameters and OOM error cases"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- args = dbus.Dictionary({ 'ssid': "foo1", 'key_mgmt': 'NONE',
- 'identity': "testuser", 'scan_freq': '2412' },
- signature='sv')
- netw1 = iface.AddNetwork(args)
- net_obj = bus.get_object(WPAS_DBUS_SERVICE, netw1)
- with alloc_fail_dbus(dev[0], 1,
- "wpa_config_get_all;wpas_dbus_getter_network_properties",
- "Get"):
- net_obj.Get(WPAS_DBUS_NETWORK, "Properties",
- dbus_interface=dbus.PROPERTIES_IFACE)
- iface.RemoveAllNetworks()
- with alloc_fail_dbus(dev[0], 1,
- "wpas_dbus_new_decompose_object_path;wpas_dbus_handler_remove_network",
- "RemoveNetwork", "InvalidArgs"):
- iface.RemoveNetwork(dbus.ObjectPath("/fi/w1/wpa_supplicant1/Interfaces/1234/Networks/1234"))
- with alloc_fail(dev[0], 1, "wpa_dbus_register_object_per_iface;wpas_dbus_register_network"):
- args = dbus.Dictionary({ 'ssid': "foo2", 'key_mgmt': 'NONE' },
- signature='sv')
- try:
- netw = iface.AddNetwork(args)
- # Currently, AddNetwork() succeeds even if os_strdup() for path
- # fails, so remove the network if that occurs.
- iface.RemoveNetwork(netw)
- except dbus.exceptions.DBusException, e:
- pass
- for i in range(1, 3):
- with alloc_fail(dev[0], i, "=wpas_dbus_register_network"):
- try:
- netw = iface.AddNetwork(args)
- # Currently, AddNetwork() succeeds even if network registration
- # fails, so remove the network if that occurs.
- iface.RemoveNetwork(netw)
- except dbus.exceptions.DBusException, e:
- pass
- with alloc_fail_dbus(dev[0], 1,
- "=wpa_config_add_network;wpas_dbus_handler_add_network",
- "AddNetwork",
- "UnknownError: wpa_supplicant could not add a network"):
- args = dbus.Dictionary({ 'ssid': "foo2", 'key_mgmt': 'NONE' },
- signature='sv')
- netw = iface.AddNetwork(args)
- tests = [ (1,
- 'wpa_dbus_dict_get_entry;set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'ssid': dbus.ByteArray(' ') },
- signature='sv')),
- (1, '=set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'ssid': 'foo' }, signature='sv')),
- (1, '=set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'eap': 'foo' }, signature='sv')),
- (1, '=set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'priority': dbus.UInt32(1) },
- signature='sv')),
- (1, '=set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'priority': dbus.Int32(1) },
- signature='sv')),
- (1, '=set_network_properties;wpas_dbus_handler_add_network',
- dbus.Dictionary({ 'ssid': dbus.ByteArray(' ') },
- signature='sv')) ]
- for (count,funcs,args) in tests:
- with alloc_fail_dbus(dev[0], count, funcs, "AddNetwork", "InvalidArgs"):
- netw = iface.AddNetwork(args)
- if len(if_obj.Get(WPAS_DBUS_IFACE, 'Networks',
- dbus_interface=dbus.PROPERTIES_IFACE)) > 0:
- raise Exception("Unexpected network block added")
- if len(dev[0].list_networks()) > 0:
- raise Exception("Unexpected network block visible")
- def test_dbus_interface(dev, apdev):
- """D-Bus CreateInterface/GetInterface/RemoveInterface parameters and error cases"""
- try:
- _test_dbus_interface(dev, apdev)
- finally:
- # Need to force P2P channel list update since the 'lo' interface
- # with driver=none ends up configuring default dualband channels.
- dev[0].request("SET country US")
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- if ev is None:
- ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"],
- timeout=1)
- dev[0].request("SET country 00")
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- if ev is None:
- ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"],
- timeout=1)
- subprocess.call(['iw', 'reg', 'set', '00'])
- def _test_dbus_interface(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wpas = dbus.Interface(wpas_obj, WPAS_DBUS_SERVICE)
- params = dbus.Dictionary({ 'Ifname': 'lo', 'Driver': 'none' },
- signature='sv')
- path = wpas.CreateInterface(params)
- logger.debug("New interface path: " + str(path))
- path2 = wpas.GetInterface("lo")
- if path != path2:
- raise Exception("Interface object mismatch")
- params = dbus.Dictionary({ 'Ifname': 'lo',
- 'Driver': 'none',
- 'ConfigFile': 'foo',
- 'BridgeIfname': 'foo', },
- signature='sv')
- try:
- wpas.CreateInterface(params)
- raise Exception("Invalid CreateInterface() accepted")
- except dbus.exceptions.DBusException, e:
- if "InterfaceExists" not in str(e):
- raise Exception("Unexpected error message for invalid CreateInterface: " + str(e))
- wpas.RemoveInterface(path)
- try:
- wpas.RemoveInterface(path)
- raise Exception("Invalid RemoveInterface() accepted")
- except dbus.exceptions.DBusException, e:
- if "InterfaceUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveInterface: " + str(e))
- params = dbus.Dictionary({ 'Ifname': 'lo', 'Driver': 'none',
- 'Foo': 123 },
- signature='sv')
- try:
- wpas.CreateInterface(params)
- raise Exception("Invalid CreateInterface() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid CreateInterface: " + str(e))
- params = dbus.Dictionary({ 'Driver': 'none' }, signature='sv')
- try:
- wpas.CreateInterface(params)
- raise Exception("Invalid CreateInterface() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid CreateInterface: " + str(e))
- try:
- wpas.GetInterface("lo")
- raise Exception("Invalid GetInterface() accepted")
- except dbus.exceptions.DBusException, e:
- if "InterfaceUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveInterface: " + str(e))
- def test_dbus_interface_oom(dev, apdev):
- """D-Bus CreateInterface/GetInterface/RemoveInterface OOM error cases"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wpas = dbus.Interface(wpas_obj, WPAS_DBUS_SERVICE)
- with alloc_fail_dbus(dev[0], 1, "wpa_dbus_dict_get_entry;wpas_dbus_handler_create_interface", "CreateInterface", "InvalidArgs"):
- params = dbus.Dictionary({ 'Ifname': 'lo', 'Driver': 'none' },
- signature='sv')
- wpas.CreateInterface(params)
- for i in range(1, 1000):
- dev[0].request("TEST_ALLOC_FAIL %d:wpa_supplicant_add_iface;wpas_dbus_handler_create_interface" % i)
- params = dbus.Dictionary({ 'Ifname': 'lo', 'Driver': 'none' },
- signature='sv')
- try:
- npath = wpas.CreateInterface(params)
- wpas.RemoveInterface(npath)
- logger.info("CreateInterface succeeds after %d allocation failures" % i)
- state = dev[0].request('GET_ALLOC_FAIL')
- logger.info("GET_ALLOC_FAIL: " + state)
- dev[0].dump_monitor()
- dev[0].request("TEST_ALLOC_FAIL 0:")
- if i < 5:
- raise Exception("CreateInterface succeeded during out-of-memory")
- if not state.startswith('0:'):
- break
- except dbus.exceptions.DBusException, e:
- pass
- for arg in [ 'Driver', 'Ifname', 'ConfigFile', 'BridgeIfname' ]:
- with alloc_fail_dbus(dev[0], 1, "=wpas_dbus_handler_create_interface",
- "CreateInterface"):
- params = dbus.Dictionary({ arg: 'foo' }, signature='sv')
- wpas.CreateInterface(params)
- def test_dbus_blob(dev, apdev):
- """D-Bus AddNetwork/RemoveNetwork parameters and error cases"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- blob = dbus.ByteArray("\x01\x02\x03")
- iface.AddBlob('blob1', blob)
- try:
- iface.AddBlob('blob1', dbus.ByteArray("\x01\x02\x04"))
- raise Exception("Invalid AddBlob() accepted")
- except dbus.exceptions.DBusException, e:
- if "BlobExists" not in str(e):
- raise Exception("Unexpected error message for invalid AddBlob: " + str(e))
- res = iface.GetBlob('blob1')
- if len(res) != len(blob):
- raise Exception("Unexpected blob data length")
- for i in range(len(res)):
- if res[i] != dbus.Byte(blob[i]):
- raise Exception("Unexpected blob data")
- res = if_obj.Get(WPAS_DBUS_IFACE, "Blobs",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if 'blob1' not in res:
- raise Exception("Added blob missing from Blobs property")
- iface.RemoveBlob('blob1')
- try:
- iface.RemoveBlob('blob1')
- raise Exception("Invalid RemoveBlob() accepted")
- except dbus.exceptions.DBusException, e:
- if "BlobUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveBlob: " + str(e))
- try:
- iface.GetBlob('blob1')
- raise Exception("Invalid GetBlob() accepted")
- except dbus.exceptions.DBusException, e:
- if "BlobUnknown" not in str(e):
- raise Exception("Unexpected error message for invalid GetBlob: " + str(e))
- class TestDbusBlob(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.blob_added = False
- self.blob_removed = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_blob)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.blobAdded, WPAS_DBUS_IFACE, "BlobAdded")
- self.add_signal(self.blobRemoved, WPAS_DBUS_IFACE, "BlobRemoved")
- self.loop.run()
- return self
- def blobAdded(self, blobName):
- logger.debug("blobAdded: %s" % blobName)
- if blobName == 'blob2':
- self.blob_added = True
- def blobRemoved(self, blobName):
- logger.debug("blobRemoved: %s" % blobName)
- if blobName == 'blob2':
- self.blob_removed = True
- self.loop.quit()
- def run_blob(self, *args):
- logger.debug("run_blob")
- iface.AddBlob('blob2', dbus.ByteArray("\x01\x02\x04"))
- iface.RemoveBlob('blob2')
- return False
- def success(self):
- return self.blob_added and self.blob_removed
- with TestDbusBlob(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_blob_oom(dev, apdev):
- """D-Bus AddNetwork/RemoveNetwork OOM error cases"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- for i in range(1, 4):
- with alloc_fail_dbus(dev[0], i, "wpas_dbus_handler_add_blob",
- "AddBlob"):
- iface.AddBlob('blob_no_mem', dbus.ByteArray("\x01\x02\x03\x04"))
- def test_dbus_autoscan(dev, apdev):
- """D-Bus Autoscan()"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- iface.AutoScan("foo")
- iface.AutoScan("periodic:1")
- iface.AutoScan("")
- dev[0].request("AUTOSCAN ")
- def test_dbus_autoscan_oom(dev, apdev):
- """D-Bus Autoscan() OOM"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- with alloc_fail_dbus(dev[0], 1, "wpas_dbus_handler_autoscan", "AutoScan"):
- iface.AutoScan("foo")
- dev[0].request("AUTOSCAN ")
- def test_dbus_tdls_invalid(dev, apdev):
- """D-Bus invalid TDLS operations"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
- connect_2sta_open(dev, hapd)
- addr1 = dev[1].p2p_interface_addr()
- try:
- iface.TDLSDiscover("foo")
- raise Exception("Invalid TDLSDiscover() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid TDLSDiscover: " + str(e))
- try:
- iface.TDLSStatus("foo")
- raise Exception("Invalid TDLSStatus() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid TDLSStatus: " + str(e))
- res = iface.TDLSStatus(addr1)
- if res != "peer does not exist":
- raise Exception("Unexpected TDLSStatus response")
- try:
- iface.TDLSSetup("foo")
- raise Exception("Invalid TDLSSetup() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid TDLSSetup: " + str(e))
- try:
- iface.TDLSTeardown("foo")
- raise Exception("Invalid TDLSTeardown() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid TDLSTeardown: " + str(e))
- try:
- iface.TDLSTeardown("00:11:22:33:44:55")
- raise Exception("TDLSTeardown accepted for unknown peer")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: error performing TDLS teardown" not in str(e):
- raise Exception("Unexpected error message: " + str(e))
- def test_dbus_tdls_oom(dev, apdev):
- """D-Bus TDLS operations during OOM"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- with alloc_fail_dbus(dev[0], 1, "wpa_tdls_add_peer", "TDLSSetup",
- "UnknownError: error performing TDLS setup"):
- iface.TDLSSetup("00:11:22:33:44:55")
- def test_dbus_tdls(dev, apdev):
- """D-Bus TDLS"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
- connect_2sta_open(dev, hapd)
- addr1 = dev[1].p2p_interface_addr()
- class TestDbusTdls(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.tdls_setup = False
- self.tdls_teardown = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_tdls)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- def run_tdls(self, *args):
- logger.debug("run_tdls")
- iface.TDLSDiscover(addr1)
- gobject.timeout_add(100, self.run_tdls2)
- return False
- def run_tdls2(self, *args):
- logger.debug("run_tdls2")
- iface.TDLSSetup(addr1)
- gobject.timeout_add(500, self.run_tdls3)
- return False
- def run_tdls3(self, *args):
- logger.debug("run_tdls3")
- res = iface.TDLSStatus(addr1)
- if res == "connected":
- self.tdls_setup = True
- else:
- logger.info("Unexpected TDLSStatus: " + res)
- iface.TDLSTeardown(addr1)
- gobject.timeout_add(200, self.run_tdls4)
- return False
- def run_tdls4(self, *args):
- logger.debug("run_tdls4")
- res = iface.TDLSStatus(addr1)
- if res == "peer does not exist":
- self.tdls_teardown = True
- else:
- logger.info("Unexpected TDLSStatus: " + res)
- self.loop.quit()
- return False
- def success(self):
- return self.tdls_setup and self.tdls_teardown
- with TestDbusTdls(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_pkcs11(dev, apdev):
- """D-Bus SetPKCS11EngineAndModulePath()"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- try:
- iface.SetPKCS11EngineAndModulePath("foo", "bar")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: Reinit of the EAPOL" not in str(e):
- raise Exception("Unexpected error message for invalid SetPKCS11EngineAndModulePath: " + str(e))
- try:
- iface.SetPKCS11EngineAndModulePath("foo", "")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: Reinit of the EAPOL" not in str(e):
- raise Exception("Unexpected error message for invalid SetPKCS11EngineAndModulePath: " + str(e))
- iface.SetPKCS11EngineAndModulePath("", "bar")
- res = if_obj.Get(WPAS_DBUS_IFACE, "PKCS11EnginePath",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != "":
- raise Exception("Unexpected PKCS11EnginePath value: " + res)
- res = if_obj.Get(WPAS_DBUS_IFACE, "PKCS11ModulePath",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != "bar":
- raise Exception("Unexpected PKCS11ModulePath value: " + res)
- iface.SetPKCS11EngineAndModulePath("", "")
- res = if_obj.Get(WPAS_DBUS_IFACE, "PKCS11EnginePath",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != "":
- raise Exception("Unexpected PKCS11EnginePath value: " + res)
- res = if_obj.Get(WPAS_DBUS_IFACE, "PKCS11ModulePath",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != "":
- raise Exception("Unexpected PKCS11ModulePath value: " + res)
- def test_dbus_apscan(dev, apdev):
- """D-Bus Get/Set ApScan"""
- try:
- _test_dbus_apscan(dev, apdev)
- finally:
- dev[0].request("AP_SCAN 1")
- def _test_dbus_apscan(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- res = if_obj.Get(WPAS_DBUS_IFACE, "ApScan",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != 1:
- raise Exception("Unexpected initial ApScan value: %d" % res)
- for i in range(3):
- if_obj.Set(WPAS_DBUS_IFACE, "ApScan", dbus.UInt32(i),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "ApScan",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != i:
- raise Exception("Unexpected ApScan value %d (expected %d)" % (res, i))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "ApScan", dbus.Int16(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(ApScan,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(ApScan,-1): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "ApScan", dbus.UInt32(123),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(ApScan,123) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: ap_scan must be 0, 1, or 2" not in str(e):
- raise Exception("Unexpected error message for invalid Set(ApScan,123): " + str(e))
- if_obj.Set(WPAS_DBUS_IFACE, "ApScan", dbus.UInt32(1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- def test_dbus_fastreauth(dev, apdev):
- """D-Bus Get/Set FastReauth"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- res = if_obj.Get(WPAS_DBUS_IFACE, "FastReauth",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != True:
- raise Exception("Unexpected initial FastReauth value: " + str(res))
- for i in [ False, True ]:
- if_obj.Set(WPAS_DBUS_IFACE, "FastReauth", dbus.Boolean(i),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "FastReauth",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != i:
- raise Exception("Unexpected FastReauth value %d (expected %d)" % (res, i))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "FastReauth", dbus.Int16(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(FastReauth,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(ApScan,-1): " + str(e))
- if_obj.Set(WPAS_DBUS_IFACE, "FastReauth", dbus.Boolean(True),
- dbus_interface=dbus.PROPERTIES_IFACE)
- def test_dbus_bss_expire(dev, apdev):
- """D-Bus Get/Set BSSExpireAge and BSSExpireCount"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireAge", dbus.UInt32(179),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "BSSExpireAge",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != 179:
- raise Exception("Unexpected BSSExpireAge value %d (expected %d)" % (res, i))
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireCount", dbus.UInt32(3),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "BSSExpireCount",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != 3:
- raise Exception("Unexpected BSSExpireCount value %d (expected %d)" % (res, i))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireAge", dbus.Int16(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(BSSExpireAge,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(BSSExpireAge,-1): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireAge", dbus.UInt32(9),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(BSSExpireAge,9) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: BSSExpireAge must be >= 10" not in str(e):
- raise Exception("Unexpected error message for invalid Set(BSSExpireAge,9): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireCount", dbus.Int16(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(BSSExpireCount,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(BSSExpireCount,-1): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireCount", dbus.UInt32(0),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(BSSExpireCount,0) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: BSSExpireCount must be > 0" not in str(e):
- raise Exception("Unexpected error message for invalid Set(BSSExpireCount,0): " + str(e))
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireAge", dbus.UInt32(180),
- dbus_interface=dbus.PROPERTIES_IFACE)
- if_obj.Set(WPAS_DBUS_IFACE, "BSSExpireCount", dbus.UInt32(2),
- dbus_interface=dbus.PROPERTIES_IFACE)
- def test_dbus_country(dev, apdev):
- """D-Bus Get/Set Country"""
- try:
- _test_dbus_country(dev, apdev)
- finally:
- dev[0].request("SET country 00")
- subprocess.call(['iw', 'reg', 'set', '00'])
- def _test_dbus_country(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- # work around issues with possible pending regdom event from the end of
- # the previous test case
- time.sleep(0.2)
- dev[0].dump_monitor()
- if_obj.Set(WPAS_DBUS_IFACE, "Country", "FI",
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "Country",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != "FI":
- raise Exception("Unexpected Country value %s (expected FI)" % res)
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"])
- if ev is None:
- # For now, work around separate P2P Device interface event delivery
- ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- if ev is None:
- raise Exception("regdom change event not seen")
- if "init=USER type=COUNTRY alpha2=FI" not in ev:
- raise Exception("Unexpected event contents: " + ev)
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "Country", dbus.Int16(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(Country,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(Country,-1): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "Country", "F",
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(Country,F) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: invalid country code" not in str(e):
- raise Exception("Unexpected error message for invalid Set(Country,F): " + str(e))
- if_obj.Set(WPAS_DBUS_IFACE, "Country", "00",
- dbus_interface=dbus.PROPERTIES_IFACE)
- ev = dev[0].wait_event(["CTRL-EVENT-REGDOM-CHANGE"])
- if ev is None:
- # For now, work around separate P2P Device interface event delivery
- ev = dev[0].wait_global_event(["CTRL-EVENT-REGDOM-CHANGE"], timeout=1)
- if ev is None:
- raise Exception("regdom change event not seen")
- # init=CORE was previously used due to invalid db.txt data for 00. For
- # now, allow both it and the new init=USER after fixed db.txt.
- if "init=CORE type=WORLD" not in ev and "init=USER type=WORLD" not in ev:
- raise Exception("Unexpected event contents: " + ev)
- def test_dbus_scan_interval(dev, apdev):
- """D-Bus Get/Set ScanInterval"""
- try:
- _test_dbus_scan_interval(dev, apdev)
- finally:
- dev[0].request("SCAN_INTERVAL 5")
- def _test_dbus_scan_interval(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- if_obj.Set(WPAS_DBUS_IFACE, "ScanInterval", dbus.Int32(3),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = if_obj.Get(WPAS_DBUS_IFACE, "ScanInterval",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if res != 3:
- raise Exception("Unexpected ScanInterval value %d (expected %d)" % (res, i))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "ScanInterval", dbus.UInt16(100),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(ScanInterval,100) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: wrong property type" not in str(e):
- raise Exception("Unexpected error message for invalid Set(ScanInterval,100): " + str(e))
- try:
- if_obj.Set(WPAS_DBUS_IFACE, "ScanInterval", dbus.Int32(-1),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(ScanInterval,-1) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: scan_interval must be >= 0" not in str(e):
- raise Exception("Unexpected error message for invalid Set(ScanInterval,-1): " + str(e))
- if_obj.Set(WPAS_DBUS_IFACE, "ScanInterval", dbus.Int32(5),
- dbus_interface=dbus.PROPERTIES_IFACE)
- def test_dbus_probe_req_reporting(dev, apdev):
- """D-Bus Probe Request reporting"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- dev[1].p2p_find(social=True)
- class TestDbusProbe(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.reported = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.probeRequest, WPAS_DBUS_IFACE, "ProbeRequest",
- byte_arrays=True)
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- self.iface = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE)
- self.iface.SubscribeProbeReq()
- self.group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- def probeRequest(self, args):
- logger.debug("probeRequest: args=%s" % str(args))
- self.reported = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- params = dbus.Dictionary({ 'frequency': 2412 })
- p2p.GroupAdd(params)
- return False
- def success(self):
- return self.reported
- with TestDbusProbe(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- t.iface.UnsubscribeProbeReq()
- try:
- t.iface.UnsubscribeProbeReq()
- raise Exception("Invalid UnsubscribeProbeReq() accepted")
- except dbus.exceptions.DBusException, e:
- if "NoSubscription" not in str(e):
- raise Exception("Unexpected error message for invalid UnsubscribeProbeReq(): " + str(e))
- t.group_p2p.Disconnect()
- with TestDbusProbe(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- # On purpose, leave ProbeReq subscription in place to test automatic
- # cleanup.
- dev[1].p2p_stop_find()
- def test_dbus_probe_req_reporting_oom(dev, apdev):
- """D-Bus Probe Request reporting (OOM)"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- # Need to make sure this process has not already subscribed to avoid false
- # failures due to the operation succeeding due to os_strdup() not even
- # getting called.
- try:
- iface.UnsubscribeProbeReq()
- was_subscribed = True
- except dbus.exceptions.DBusException, e:
- was_subscribed = False
- pass
- with alloc_fail_dbus(dev[0], 1, "wpas_dbus_handler_subscribe_preq",
- "SubscribeProbeReq"):
- iface.SubscribeProbeReq()
- if was_subscribed:
- # On purpose, leave ProbeReq subscription in place to test automatic
- # cleanup.
- iface.SubscribeProbeReq()
- def test_dbus_p2p_invalid(dev, apdev):
- """D-Bus invalid P2P operations"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- try:
- p2p.RejectPeer(path + "/Peers/00112233445566")
- raise Exception("Invalid RejectPeer accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: Failed to call wpas_p2p_reject" not in str(e):
- raise Exception("Unexpected error message for invalid RejectPeer(): " + str(e))
- try:
- p2p.RejectPeer("/foo")
- raise Exception("Invalid RejectPeer accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid RejectPeer(): " + str(e))
- tests = [ { },
- { 'peer': 'foo' },
- { 'foo': "bar" },
- { 'iface': "abc" },
- { 'iface': 123 } ]
- for t in tests:
- try:
- p2p.RemoveClient(t)
- raise Exception("Invalid RemoveClient accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid RemoveClient(): " + str(e))
- tests = [ {'DiscoveryType': 'foo'},
- {'RequestedDeviceTypes': 'foo'},
- {'RequestedDeviceTypes': ['foo']},
- {'RequestedDeviceTypes': ['1','2','3','4','5','6','7','8','9',
- '10','11','12','13','14','15','16',
- '17']},
- {'RequestedDeviceTypes': dbus.Array([], signature="s")},
- {'RequestedDeviceTypes': dbus.Array([['foo']], signature="as")},
- {'RequestedDeviceTypes': dbus.Array([], signature="i")},
- {'RequestedDeviceTypes': [dbus.ByteArray('12345678'),
- dbus.ByteArray('1234567')]},
- {'Foo': dbus.Int16(1)},
- {'Foo': dbus.UInt16(1)},
- {'Foo': dbus.Int64(1)},
- {'Foo': dbus.UInt64(1)},
- {'Foo': dbus.Double(1.23)},
- {'Foo': dbus.Signature('s')},
- {'Foo': 'bar'}]
- for t in tests:
- try:
- p2p.Find(dbus.Dictionary(t))
- raise Exception("Invalid Find accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Find(): " + str(e))
- for p in [ "/foo",
- "/fi/w1/wpa_supplicant1/Interfaces/1234",
- "/fi/w1/wpa_supplicant1/Interfaces/1234/Networks/1234" ]:
- try:
- p2p.RemovePersistentGroup(dbus.ObjectPath(p))
- raise Exception("Invalid RemovePersistentGroup accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid RemovePersistentGroup: " + str(e))
- try:
- dev[0].request("P2P_SET disabled 1")
- p2p.Listen(5)
- raise Exception("Invalid Listen accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: Could not start P2P listen" not in str(e):
- raise Exception("Unexpected error message for invalid Listen: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- test_obj = bus.get_object(WPAS_DBUS_SERVICE, path, introspect=False)
- test_p2p = dbus.Interface(test_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- try:
- test_p2p.Listen("foo")
- raise Exception("Invalid Listen accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Listen: " + str(e))
- try:
- dev[0].request("P2P_SET disabled 1")
- p2p.ExtendedListen(dbus.Dictionary({}))
- raise Exception("Invalid ExtendedListen accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: failed to initiate a p2p_ext_listen" not in str(e):
- raise Exception("Unexpected error message for invalid ExtendedListen: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- try:
- dev[0].request("P2P_SET disabled 1")
- args = { 'duration1': 30000, 'interval1': 102400,
- 'duration2': 20000, 'interval2': 102400 }
- p2p.PresenceRequest(args)
- raise Exception("Invalid PresenceRequest accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: Failed to invoke presence request" not in str(e):
- raise Exception("Unexpected error message for invalid PresenceRequest: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- try:
- params = dbus.Dictionary({'frequency': dbus.Int32(-1)})
- p2p.GroupAdd(params)
- raise Exception("Invalid GroupAdd accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid GroupAdd: " + str(e))
- try:
- params = dbus.Dictionary({'persistent_group_object':
- dbus.ObjectPath(path),
- 'frequency': 2412})
- p2p.GroupAdd(params)
- raise Exception("Invalid GroupAdd accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid GroupAdd: " + str(e))
- try:
- p2p.Disconnect()
- raise Exception("Invalid Disconnect accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: failed to disconnect" not in str(e):
- raise Exception("Unexpected error message for invalid Disconnect: " + str(e))
- try:
- dev[0].request("P2P_SET disabled 1")
- p2p.Flush()
- raise Exception("Invalid Flush accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Flush: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- try:
- dev[0].request("P2P_SET disabled 1")
- args = { 'peer': path,
- 'join': True,
- 'wps_method': 'pbc',
- 'frequency': 2412 }
- pin = p2p.Connect(args)
- raise Exception("Invalid Connect accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Connect: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- tests = [ { 'frequency': dbus.Int32(-1) },
- { 'wps_method': 'pbc' },
- { 'wps_method': 'foo' } ]
- for args in tests:
- try:
- pin = p2p.Connect(args)
- raise Exception("Invalid Connect accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Connect: " + str(e))
- try:
- dev[0].request("P2P_SET disabled 1")
- args = { 'peer': path }
- pin = p2p.Invite(args)
- raise Exception("Invalid Invite accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Invite: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- try:
- args = { 'foo': 'bar' }
- pin = p2p.Invite(args)
- raise Exception("Invalid Invite accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Connect: " + str(e))
- tests = [ (path, 'display', "InvalidArgs"),
- (dbus.ObjectPath(path + "/Peers/00112233445566"),
- 'display',
- "UnknownError: Failed to send provision discovery request"),
- (dbus.ObjectPath(path + "/Peers/00112233445566"),
- 'keypad',
- "UnknownError: Failed to send provision discovery request"),
- (dbus.ObjectPath(path + "/Peers/00112233445566"),
- 'pbc',
- "UnknownError: Failed to send provision discovery request"),
- (dbus.ObjectPath(path + "/Peers/00112233445566"),
- 'pushbutton',
- "UnknownError: Failed to send provision discovery request"),
- (dbus.ObjectPath(path + "/Peers/00112233445566"),
- 'foo', "InvalidArgs") ]
- for (p,method,err) in tests:
- try:
- p2p.ProvisionDiscoveryRequest(p, method)
- raise Exception("Invalid ProvisionDiscoveryRequest accepted")
- except dbus.exceptions.DBusException, e:
- if err not in str(e):
- raise Exception("Unexpected error message for invalid ProvisionDiscoveryRequest: " + str(e))
- try:
- dev[0].request("P2P_SET disabled 1")
- if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Peers",
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Get(Peers) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Get(Peers): " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- def test_dbus_p2p_oom(dev, apdev):
- """D-Bus P2P operations and OOM"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_entry_get_string_array",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ 'bar' ] }))
- with alloc_fail_dbus(dev[0], 2, "_wpa_dbus_dict_entry_get_string_array",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ 'bar' ] }))
- with alloc_fail_dbus(dev[0], 10, "_wpa_dbus_dict_entry_get_string_array",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ '1','2','3','4','5','6','7','8','9' ] }))
- with alloc_fail_dbus(dev[0], 1, ":=_wpa_dbus_dict_entry_get_binarray",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] }))
- with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_entry_get_byte_array;_wpa_dbus_dict_entry_get_binarray",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] }))
- with alloc_fail_dbus(dev[0], 2, "=_wpa_dbus_dict_entry_get_binarray",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123'),
- dbus.ByteArray('123') ] }))
- with alloc_fail_dbus(dev[0], 1, "wpabuf_alloc_ext_data;_wpa_dbus_dict_entry_get_binarray",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': [ dbus.ByteArray('123') ] }))
- with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_fill_value_from_variant;wpas_dbus_handler_p2p_find",
- "Find", "InvalidArgs"):
- p2p.Find(dbus.Dictionary({ 'Foo': path }))
- with alloc_fail_dbus(dev[0], 1, "_wpa_dbus_dict_entry_get_byte_array",
- "AddService", "InvalidArgs"):
- args = { 'service_type': 'bonjour',
- 'response': dbus.ByteArray(500*'b') }
- p2p.AddService(args)
- with alloc_fail_dbus(dev[0], 2, "_wpa_dbus_dict_entry_get_byte_array",
- "AddService", "InvalidArgs"):
- p2p.AddService(args)
- def test_dbus_p2p_discovery(dev, apdev):
- """D-Bus P2P discovery"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].request("SET sec_device_type 1-0050F204-2")
- dev[1].request("VENDOR_ELEM_ADD 1 dd0c0050f2041049000411223344")
- dev[1].p2p_listen()
- addr1 = dev[1].p2p_dev_addr()
- a1 = binascii.unhexlify(addr1.replace(':',''))
- wfd_devinfo = "00001c440028"
- dev[2].request("SET wifi_display 1")
- dev[2].request("WFD_SUBELEM_SET 0 0006" + wfd_devinfo)
- wfd = binascii.unhexlify('000006' + wfd_devinfo)
- dev[2].p2p_listen()
- addr2 = dev[2].p2p_dev_addr()
- a2 = binascii.unhexlify(addr2.replace(':',''))
- res = if_obj.GetAll(WPAS_DBUS_IFACE_P2PDEVICE,
- dbus_interface=dbus.PROPERTIES_IFACE)
- if 'Peers' not in res:
- raise Exception("GetAll result missing Peers")
- if len(res['Peers']) != 0:
- raise Exception("Unexpected peer(s) in the list")
- args = {'DiscoveryType': 'social',
- 'RequestedDeviceTypes': [dbus.ByteArray('12345678')],
- 'Timeout': dbus.Int32(1) }
- p2p.Find(dbus.Dictionary(args))
- p2p.StopFind()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.found = False
- self.found2 = False
- self.found_prop = False
- self.lost = False
- self.find_stopped = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.deviceFoundProperties,
- WPAS_DBUS_IFACE_P2PDEVICE, "DeviceFoundProperties")
- self.add_signal(self.deviceLost, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceLost")
- self.add_signal(self.provisionDiscoveryResponseEnterPin,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ProvisionDiscoveryResponseEnterPin")
- self.add_signal(self.findStopped, WPAS_DBUS_IFACE_P2PDEVICE,
- "FindStopped")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- res = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Peers",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) < 1:
- raise Exception("Unexpected number of peers")
- if path not in res:
- raise Exception("Mismatch in peer object path")
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- res = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("peer properties: " + str(res))
- if res['DeviceAddress'] == a1:
- if 'SecondaryDeviceTypes' not in res:
- raise Exception("Missing SecondaryDeviceTypes")
- sec = res['SecondaryDeviceTypes']
- if len(sec) < 1:
- raise Exception("Secondary device type missing")
- if "\x00\x01\x00\x50\xF2\x04\x00\x02" not in sec:
- raise Exception("Secondary device type mismatch")
- if 'VendorExtension' not in res:
- raise Exception("Missing VendorExtension")
- vendor = res['VendorExtension']
- if len(vendor) < 1:
- raise Exception("Vendor extension missing")
- if "\x11\x22\x33\x44" not in vendor:
- raise Exception("Secondary device type mismatch")
- self.found = True
- elif res['DeviceAddress'] == a2:
- if 'IEs' not in res:
- raise Exception("IEs missing")
- if res['IEs'] != wfd:
- raise Exception("IEs mismatch")
- self.found2 = True
- else:
- raise Exception("Unexpected peer device address")
- if self.found and self.found2:
- p2p.StopFind()
- p2p.RejectPeer(path)
- p2p.ProvisionDiscoveryRequest(path, 'display')
- def deviceLost(self, path):
- logger.debug("deviceLost: path=%s" % path)
- self.lost = True
- try:
- p2p.RejectPeer(path)
- raise Exception("Invalid RejectPeer accepted")
- except dbus.exceptions.DBusException, e:
- if "UnknownError: Failed to call wpas_p2p_reject" not in str(e):
- raise Exception("Unexpected error message for invalid RejectPeer(): " + str(e))
- self.loop.quit()
- def deviceFoundProperties(self, path, properties):
- logger.debug("deviceFoundProperties: path=%s" % path)
- logger.debug("peer properties: " + str(properties))
- if properties['DeviceAddress'] == a1:
- self.found_prop = True
- def provisionDiscoveryResponseEnterPin(self, peer_object):
- logger.debug("provisionDiscoveryResponseEnterPin - peer=%s" % peer_object)
- p2p.Flush()
- def findStopped(self):
- logger.debug("findStopped")
- self.find_stopped = True
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social',
- 'Timeout': dbus.Int32(10)}))
- return False
- def success(self):
- return self.found and self.lost and self.found2 and self.find_stopped
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].request("VENDOR_ELEM_REMOVE 1 *")
- dev[1].p2p_stop_find()
- p2p.Listen(1)
- dev[2].p2p_stop_find()
- dev[2].request("P2P_FLUSH")
- if not dev[2].discover_peer(addr0):
- raise Exception("Peer not found")
- p2p.StopFind()
- dev[2].p2p_stop_find()
- try:
- p2p.ExtendedListen(dbus.Dictionary({'foo': 100}))
- raise Exception("Invalid ExtendedListen accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid ExtendedListen(): " + str(e))
- p2p.ExtendedListen(dbus.Dictionary({'period': 100, 'interval': 1000}))
- p2p.ExtendedListen(dbus.Dictionary({}))
- dev[0].global_request("P2P_EXT_LISTEN")
- def test_dbus_p2p_service_discovery(dev, apdev):
- """D-Bus P2P service discovery"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- addr1 = dev[1].p2p_dev_addr()
- bonjour_query = dbus.ByteArray(binascii.unhexlify('0b5f6166706f766572746370c00c000c01'))
- bonjour_response = dbus.ByteArray(binascii.unhexlify('074578616d706c65c027'))
-
- args = { 'service_type': 'bonjour',
- 'query': bonjour_query,
- 'response': bonjour_response }
- p2p.AddService(args)
- p2p.FlushService()
- p2p.AddService(args)
- try:
- p2p.DeleteService(args)
- raise Exception("Invalid DeleteService() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid DeleteService(): " + str(e))
- args = { 'service_type': 'bonjour',
- 'query': bonjour_query }
- p2p.DeleteService(args)
- try:
- p2p.DeleteService(args)
- raise Exception("Invalid DeleteService() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid DeleteService(): " + str(e))
- args = { 'service_type': 'upnp',
- 'version': 0x10,
- 'service': 'uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice' }
- p2p.AddService(args)
- p2p.DeleteService(args)
- try:
- p2p.DeleteService(args)
- raise Exception("Invalid DeleteService() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid DeleteService(): " + str(e))
- tests = [ { 'service_type': 'foo' },
- { 'service_type': 'foo', 'query': bonjour_query },
- { 'service_type': 'upnp' },
- { 'service_type': 'upnp', 'version': 0x10 },
- { 'service_type': 'upnp',
- 'service': 'uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice' },
- { 'version': 0x10,
- 'service': 'uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice' },
- { 'service_type': 'upnp', 'foo': 'bar' },
- { 'service_type': 'bonjour' },
- { 'service_type': 'bonjour', 'query': 'foo' },
- { 'service_type': 'bonjour', 'foo': 'bar' } ]
- for args in tests:
- try:
- p2p.DeleteService(args)
- raise Exception("Invalid DeleteService() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid DeleteService(): " + str(e))
- tests = [ { 'service_type': 'foo' },
- { 'service_type': 'upnp' },
- { 'service_type': 'upnp', 'version': 0x10 },
- { 'service_type': 'upnp',
- 'service': 'uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice' },
- { 'version': 0x10,
- 'service': 'uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice' },
- { 'service_type': 'upnp', 'foo': 'bar' },
- { 'service_type': 'bonjour' },
- { 'service_type': 'bonjour', 'query': 'foo' },
- { 'service_type': 'bonjour', 'response': 'foo' },
- { 'service_type': 'bonjour', 'query': bonjour_query },
- { 'service_type': 'bonjour', 'response': bonjour_response },
- { 'service_type': 'bonjour', 'query': dbus.ByteArray(500*'a') },
- { 'service_type': 'bonjour', 'foo': 'bar' } ]
- for args in tests:
- try:
- p2p.AddService(args)
- raise Exception("Invalid AddService() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid AddService(): " + str(e))
- args = { 'tlv': dbus.ByteArray("\x02\x00\x00\x01") }
- ref = p2p.ServiceDiscoveryRequest(args)
- p2p.ServiceDiscoveryCancelRequest(ref)
- try:
- p2p.ServiceDiscoveryCancelRequest(ref)
- raise Exception("Invalid ServiceDiscoveryCancelRequest() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid AddService(): " + str(e))
- try:
- p2p.ServiceDiscoveryCancelRequest(dbus.UInt64(0))
- raise Exception("Invalid ServiceDiscoveryCancelRequest() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid AddService(): " + str(e))
- args = { 'service_type': 'upnp',
- 'version': 0x10,
- 'service': 'ssdp:foo' }
- ref = p2p.ServiceDiscoveryRequest(args)
- p2p.ServiceDiscoveryCancelRequest(ref)
- tests = [ { 'service_type': 'foo' },
- { 'foo': 'bar' },
- { 'tlv': 'foo' },
- { },
- { 'version': 0 },
- { 'service_type': 'upnp',
- 'service': 'ssdp:foo' },
- { 'service_type': 'upnp',
- 'version': 0x10 },
- { 'service_type': 'upnp',
- 'version': 0x10,
- 'service': 'ssdp:foo',
- 'peer_object': dbus.ObjectPath(path + "/Peers") },
- { 'service_type': 'upnp',
- 'version': 0x10,
- 'service': 'ssdp:foo',
- 'peer_object': path + "/Peers" },
- { 'service_type': 'upnp',
- 'version': 0x10,
- 'service': 'ssdp:foo',
- 'peer_object': dbus.ObjectPath(path + "/Peers/00112233445566") } ]
- for args in tests:
- try:
- p2p.ServiceDiscoveryRequest(args)
- raise Exception("Invalid ServiceDiscoveryRequest accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid ServiceDiscoveryRequest(): " + str(e))
- args = { 'foo': 'bar' }
- try:
- p2p.ServiceDiscoveryResponse(dbus.Dictionary(args, signature='sv'))
- raise Exception("Invalid ServiceDiscoveryResponse accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid ServiceDiscoveryResponse(): " + str(e))
- def test_dbus_p2p_service_discovery_query(dev, apdev):
- """D-Bus P2P service discovery query"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].request("P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027")
- dev[1].p2p_listen()
- addr1 = dev[1].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.serviceDiscoveryResponse,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ServiceDiscoveryResponse", byte_arrays=True)
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- args = { 'peer_object': path,
- 'tlv': dbus.ByteArray("\x02\x00\x00\x01") }
- p2p.ServiceDiscoveryRequest(args)
- def serviceDiscoveryResponse(self, sd_request):
- logger.debug("serviceDiscoveryResponse: sd_request=%s" % str(sd_request))
- self.done = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social',
- 'Timeout': dbus.Int32(10)}))
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].p2p_stop_find()
- def test_dbus_p2p_service_discovery_external(dev, apdev):
- """D-Bus P2P service discovery with external response"""
- try:
- _test_dbus_p2p_service_discovery_external(dev, apdev)
- finally:
- dev[0].request("P2P_SERV_DISC_EXTERNAL 0")
- def _test_dbus_p2p_service_discovery_external(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- addr1 = dev[1].p2p_dev_addr()
- resp = "0300000101"
- dev[1].request("P2P_FLUSH")
- dev[1].request("P2P_SERV_DISC_REQ " + addr0 + " 02000001")
- dev[1].p2p_find(social=True)
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.sd = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.serviceDiscoveryRequest,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ServiceDiscoveryRequest")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- def serviceDiscoveryRequest(self, sd_request):
- logger.debug("serviceDiscoveryRequest: sd_request=%s" % str(sd_request))
- self.sd = True
- args = { 'peer_object': sd_request['peer_object'],
- 'frequency': sd_request['frequency'],
- 'dialog_token': sd_request['dialog_token'],
- 'tlvs': dbus.ByteArray(binascii.unhexlify(resp)) }
- p2p.ServiceDiscoveryResponse(dbus.Dictionary(args, signature='sv'))
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.ServiceDiscoveryExternal(1)
- p2p.ServiceUpdate()
- p2p.Listen(15)
- return False
- def success(self):
- return self.sd
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- ev = dev[1].wait_global_event(["P2P-SERV-DISC-RESP"], timeout=5)
- if ev is None:
- raise Exception("Service discovery timed out")
- if addr0 not in ev:
- raise Exception("Unexpected address in SD Response: " + ev)
- if ev.split(' ')[4] != resp:
- raise Exception("Unexpected response data SD Response: " + ev)
- dev[1].p2p_stop_find()
- p2p.StopFind()
- p2p.ServiceDiscoveryExternal(0)
- def test_dbus_p2p_autogo(dev, apdev):
- """D-Bus P2P autonomous GO"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.first = True
- self.waiting_end = False
- self.exceptions = False
- self.deauthorized = False
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.persistentGroupAdded,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "PersistentGroupAdded")
- self.add_signal(self.persistentGroupRemoved,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "PersistentGroupRemoved")
- self.add_signal(self.provisionDiscoveryRequestDisplayPin,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ProvisionDiscoveryRequestDisplayPin")
- self.add_signal(self.staAuthorized, WPAS_DBUS_IFACE,
- "StaAuthorized")
- self.add_signal(self.staDeauthorized, WPAS_DBUS_IFACE,
- "StaDeauthorized")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.group = properties['group_object']
- self.g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- role = self.g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Role",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if role != "GO":
- self.exceptions = True
- raise Exception("Unexpected role reported: " + role)
- group = self.g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Group",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if group != properties['group_object']:
- self.exceptions = True
- raise Exception("Unexpected Group reported: " + str(group))
- go = self.g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "PeerGO",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if go != '/':
- self.exceptions = True
- raise Exception("Unexpected PeerGO value: " + str(go))
- if self.first:
- self.first = False
- logger.info("Remove persistent group instance")
- group_p2p = dbus.Interface(self.g_if_obj,
- WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- else:
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 join")
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- if self.waiting_end:
- logger.info("Remove persistent group")
- p2p.RemovePersistentGroup(self.persistent)
- else:
- logger.info("Re-start persistent group")
- params = dbus.Dictionary({'persistent_group_object':
- self.persistent,
- 'frequency': 2412})
- p2p.GroupAdd(params)
- def persistentGroupAdded(self, path, properties):
- logger.debug("persistentGroupAdded: %s %s" % (path, str(properties)))
- self.persistent = path
- def persistentGroupRemoved(self, path):
- logger.debug("persistentGroupRemoved: %s" % path)
- self.done = True
- self.loop.quit()
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- self.peer = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug('peer properties: ' + str(self.peer))
- def provisionDiscoveryRequestDisplayPin(self, peer_object, pin):
- logger.debug("provisionDiscoveryRequestDisplayPin - peer=%s pin=%s" % (peer_object, pin))
- self.peer_path = peer_object
- peer = binascii.unhexlify(peer_object.split('/')[-1])
- addr = ""
- for p in peer:
- if len(addr) > 0:
- addr += ':'
- addr += '%02x' % ord(p)
- params = { 'Role': 'registrar',
- 'P2PDeviceAddress': self.peer['DeviceAddress'],
- 'Bssid': self.peer['DeviceAddress'],
- 'Type': 'pin' }
- wps = dbus.Interface(self.g_if_obj, WPAS_DBUS_IFACE_WPS)
- try:
- wps.Start(params)
- self.exceptions = True
- raise Exception("Invalid WPS.Start() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- self.exceptions = True
- raise Exception("Unexpected error message: " + str(e))
- params = { 'Role': 'registrar',
- 'P2PDeviceAddress': self.peer['DeviceAddress'],
- 'Type': 'pin',
- 'Pin': '12345670' }
- logger.info("Authorize peer to connect to the group")
- wps.Start(params)
- def staAuthorized(self, name):
- logger.debug("staAuthorized: " + name)
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, self.peer_path)
- res = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("Peer properties: " + str(res))
- if 'Groups' not in res or len(res['Groups']) != 1:
- self.exceptions = True
- raise Exception("Unexpected number of peer Groups entries")
- if res['Groups'][0] != self.group:
- self.exceptions = True
- raise Exception("Unexpected peer Groups[0] value")
- g_obj = bus.get_object(WPAS_DBUS_SERVICE, self.group)
- res = g_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("Group properties: " + str(res))
- if 'Members' not in res or len(res['Members']) != 1:
- self.exceptions = True
- raise Exception("Unexpected number of group members")
- ext = dbus.ByteArray("\x11\x22\x33\x44")
- # Earlier implementation of this interface was a bit strange. The
- # property is defined to have aay signature and that is what the
- # getter returned. However, the setter expected there to be a
- # dictionary with 'WPSVendorExtensions' as the key surrounding these
- # values.. The current implementations maintains support for that
- # for backwards compability reasons. Verify that encoding first.
- vals = dbus.Dictionary({ 'WPSVendorExtensions': [ ext ]},
- signature='sv')
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', vals,
- dbus_interface=dbus.PROPERTIES_IFACE)
- res = g_obj.Get(WPAS_DBUS_GROUP, 'WPSVendorExtensions',
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- if len(res) != 1:
- self.exceptions = True
- raise Exception("Unexpected number of vendor extensions")
- if res[0] != ext:
- self.exceptions = True
- raise Exception("Vendor extension value changed")
- # And now verify that the more appropriate encoding is accepted as
- # well.
- res.append(dbus.ByteArray('\xaa\xbb\xcc\xdd\xee\xff'))
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res,
- dbus_interface=dbus.PROPERTIES_IFACE)
- res2 = g_obj.Get(WPAS_DBUS_GROUP, 'WPSVendorExtensions',
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- if len(res) != 2:
- self.exceptions = True
- raise Exception("Unexpected number of vendor extensions")
- if res[0] != res2[0] or res[1] != res2[1]:
- self.exceptions = True
- raise Exception("Vendor extension value changed")
- for i in range(10):
- res.append(dbus.ByteArray('\xaa\xbb'))
- try:
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res,
- dbus_interface=dbus.PROPERTIES_IFACE)
- self.exceptions = True
- raise Exception("Invalid Set(WPSVendorExtensions) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed" not in str(e):
- self.exceptions = True
- raise Exception("Unexpected error message for invalid Set(WPSVendorExtensions): " + str(e))
- vals = dbus.Dictionary({ 'Foo': [ ext ]}, signature='sv')
- try:
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', vals,
- dbus_interface=dbus.PROPERTIES_IFACE)
- self.exceptions = True
- raise Exception("Invalid Set(WPSVendorExtensions) accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- self.exceptions = True
- raise Exception("Unexpected error message for invalid Set(WPSVendorExtensions): " + str(e))
- vals = [ "foo" ]
- try:
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', vals,
- dbus_interface=dbus.PROPERTIES_IFACE)
- self.exceptions = True
- raise Exception("Invalid Set(WPSVendorExtensions) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed" not in str(e):
- self.exceptions = True
- raise Exception("Unexpected error message for invalid Set(WPSVendorExtensions): " + str(e))
- vals = [ [ "foo" ] ]
- try:
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', vals,
- dbus_interface=dbus.PROPERTIES_IFACE)
- self.exceptions = True
- raise Exception("Invalid Set(WPSVendorExtensions) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed" not in str(e):
- self.exceptions = True
- raise Exception("Unexpected error message for invalid Set(WPSVendorExtensions): " + str(e))
- p2p.RemoveClient({ 'peer': self.peer_path })
- self.waiting_end = True
- group_p2p = dbus.Interface(self.g_if_obj,
- WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def staDeauthorized(self, name):
- logger.debug("staDeauthorized: " + name)
- self.deauthorized = True
- def run_test(self, *args):
- logger.debug("run_test")
- params = dbus.Dictionary({'persistent': True,
- 'frequency': 2412})
- logger.info("Add a persistent group")
- p2p.GroupAdd(params)
- return False
- def success(self):
- return self.done and self.deauthorized and not self.exceptions
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].wait_go_ending_session()
- def test_dbus_p2p_autogo_pbc(dev, apdev):
- """D-Bus P2P autonomous GO and PBC"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.first = True
- self.waiting_end = False
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.provisionDiscoveryPBCRequest,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ProvisionDiscoveryPBCRequest")
- self.add_signal(self.staAuthorized, WPAS_DBUS_IFACE,
- "StaAuthorized")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.group = properties['group_object']
- self.g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.global_request("P2P_CONNECT " + addr0 + " pbc join")
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- self.loop.quit()
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- self.peer = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug('peer properties: ' + str(self.peer))
- def provisionDiscoveryPBCRequest(self, peer_object):
- logger.debug("provisionDiscoveryPBCRequest - peer=%s" % peer_object)
- self.peer_path = peer_object
- peer = binascii.unhexlify(peer_object.split('/')[-1])
- addr = ""
- for p in peer:
- if len(addr) > 0:
- addr += ':'
- addr += '%02x' % ord(p)
- params = { 'Role': 'registrar',
- 'P2PDeviceAddress': self.peer['DeviceAddress'],
- 'Type': 'pbc' }
- logger.info("Authorize peer to connect to the group")
- wps = dbus.Interface(self.g_if_obj, WPAS_DBUS_IFACE_WPS)
- wps.Start(params)
- def staAuthorized(self, name):
- logger.debug("staAuthorized: " + name)
- group_p2p = dbus.Interface(self.g_if_obj,
- WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def run_test(self, *args):
- logger.debug("run_test")
- params = dbus.Dictionary({'frequency': 2412})
- p2p.GroupAdd(params)
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].wait_go_ending_session()
- dev[1].flush_scan_cache()
- def test_dbus_p2p_autogo_legacy(dev, apdev):
- """D-Bus P2P autonomous GO and legacy STA"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.staAuthorized, WPAS_DBUS_IFACE,
- "StaAuthorized")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['group_object'])
- res = g_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- bssid = ':'.join([binascii.hexlify(l) for l in res['BSSID']])
- pin = '12345670'
- params = { 'Role': 'enrollee',
- 'Type': 'pin',
- 'Pin': pin }
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- wps = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_WPS)
- wps.Start(params)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.scan_for_bss(bssid, freq=2412)
- dev1.request("WPS_PIN " + bssid + " " + pin)
- self.group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- self.loop.quit()
- def staAuthorized(self, name):
- logger.debug("staAuthorized: " + name)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.request("DISCONNECT")
- self.group_p2p.Disconnect()
- def run_test(self, *args):
- logger.debug("run_test")
- params = dbus.Dictionary({'frequency': 2412})
- p2p.GroupAdd(params)
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_join(dev, apdev):
- """D-Bus P2P join an autonomous GO"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr1 = dev[1].p2p_dev_addr()
- addr2 = dev[2].p2p_dev_addr()
- dev[1].p2p_start_go(freq=2412)
- dev1_group_ifname = dev[1].group_ifname
- dev[2].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.peer = None
- self.go = None
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.invitationResult, WPAS_DBUS_IFACE_P2PDEVICE,
- "InvitationResult")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- res = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug('peer properties: ' + str(res))
- if addr2.replace(':','') in path:
- self.peer = path
- elif addr1.replace(':','') in path:
- self.go = path
- if self.peer and self.go:
- logger.info("Join the group")
- p2p.StopFind()
- args = { 'peer': self.go,
- 'join': True,
- 'wps_method': 'pin',
- 'frequency': 2412 }
- pin = p2p.Connect(args)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_ifname = dev1_group_ifname
- dev1.group_request("WPS_PIN any " + pin)
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- role = g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Role",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if role != "client":
- raise Exception("Unexpected role reported: " + role)
- group = g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "Group",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if group != properties['group_object']:
- raise Exception("Unexpected Group reported: " + str(group))
- go = g_if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "PeerGO",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if go != self.go:
- raise Exception("Unexpected PeerGO value: " + str(go))
- g_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['group_object'])
- res = g_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("Group properties: " + str(res))
- ext = dbus.ByteArray("\x11\x22\x33\x44")
- try:
- # Set(WPSVendorExtensions) not allowed for P2P Client
- g_obj.Set(WPAS_DBUS_GROUP, 'WPSVendorExtensions', res,
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(WPSVendorExtensions) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: Failed to set property" not in str(e):
- raise Exception("Unexpected error message for invalid Set(WPSVendorExtensions): " + str(e))
- group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- args = { 'duration1': 30000, 'interval1': 102400,
- 'duration2': 20000, 'interval2': 102400 }
- group_p2p.PresenceRequest(args)
- args = { 'peer': self.peer }
- group_p2p.Invite(args)
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- self.loop.quit()
- def invitationResult(self, result):
- logger.debug("invitationResult: " + str(result))
- if result['status'] != 1:
- raise Exception("Unexpected invitation result: " + str(result))
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_ifname = dev1_group_ifname
- dev1.remove_group()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[2].p2p_stop_find()
- def test_dbus_p2p_invitation_received(dev, apdev):
- """D-Bus P2P and InvitationReceived"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- form(dev[0], dev[1])
- addr0 = dev[0].p2p_dev_addr()
- dev[0].p2p_listen()
- dev[0].global_request("SET persistent_reconnect 0")
- if not dev[1].discover_peer(addr0, social=True):
- raise Exception("Peer " + addr0 + " not found")
- peer = dev[1].get_peer(addr0)
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.invitationReceived, WPAS_DBUS_IFACE_P2PDEVICE,
- "InvitationReceived")
- self.loop.run()
- return self
- def invitationReceived(self, result):
- logger.debug("invitationReceived: " + str(result))
- self.done = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- cmd = "P2P_INVITE persistent=" + peer['persistent'] + " peer=" + addr0
- dev1.global_request(cmd)
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[0].p2p_stop_find()
- dev[1].p2p_stop_find()
- def test_dbus_p2p_config(dev, apdev):
- """D-Bus Get/Set P2PDeviceConfig"""
- try:
- _test_dbus_p2p_config(dev, apdev)
- finally:
- dev[0].request("P2P_SET ssid_postfix ")
- def _test_dbus_p2p_config(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- res = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig", res,
- dbus_interface=dbus.PROPERTIES_IFACE)
- res2 = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- if len(res) != len(res2):
- raise Exception("Different number of parameters")
- for k in res:
- if res[k] != res2[k]:
- raise Exception("Parameter %s value changes" % k)
- changes = { 'SsidPostfix': 'foo',
- 'VendorExtension': [ dbus.ByteArray('\x11\x22\x33\x44') ],
- 'SecondaryDeviceTypes': [ dbus.ByteArray('\x11\x22\x33\x44\x55\x66\x77\x88') ]}
- if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus.Dictionary(changes, signature='sv'),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res2 = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("P2PDeviceConfig: " + str(res2))
- if 'VendorExtension' not in res2 or len(res2['VendorExtension']) != 1:
- raise Exception("VendorExtension does not match")
- if 'SecondaryDeviceTypes' not in res2 or len(res2['SecondaryDeviceTypes']) != 1:
- raise Exception("SecondaryDeviceType does not match")
- changes = { 'SsidPostfix': '',
- 'VendorExtension': dbus.Array([], signature="ay"),
- 'SecondaryDeviceTypes': dbus.Array([], signature="ay") }
- if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus.Dictionary(changes, signature='sv'),
- dbus_interface=dbus.PROPERTIES_IFACE)
- res3 = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("P2PDeviceConfig: " + str(res3))
- if 'VendorExtension' in res3:
- raise Exception("VendorExtension not removed")
- if 'SecondaryDeviceTypes' in res3:
- raise Exception("SecondaryDeviceType not removed")
- try:
- dev[0].request("P2P_SET disabled 1")
- if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- raise Exception("Invalid Get(P2PDeviceConfig) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Invite: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- try:
- dev[0].request("P2P_SET disabled 1")
- changes = { 'SsidPostfix': 'foo' }
- if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus.Dictionary(changes, signature='sv'),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(P2PDeviceConfig) accepted")
- except dbus.exceptions.DBusException, e:
- if "Error.Failed: P2P is not available for this interface" not in str(e):
- raise Exception("Unexpected error message for invalid Invite: " + str(e))
- finally:
- dev[0].request("P2P_SET disabled 0")
- tests = [ { 'DeviceName': 123 },
- { 'SsidPostfix': 123 },
- { 'Foo': 'Bar' } ]
- for changes in tests:
- try:
- if_obj.Set(WPAS_DBUS_IFACE_P2PDEVICE, "P2PDeviceConfig",
- dbus.Dictionary(changes, signature='sv'),
- dbus_interface=dbus.PROPERTIES_IFACE)
- raise Exception("Invalid Set(P2PDeviceConfig) accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Invite: " + str(e))
- def test_dbus_p2p_persistent(dev, apdev):
- """D-Bus P2P persistent group"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.persistentGroupAdded,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "PersistentGroupAdded")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.loop.quit()
- def persistentGroupAdded(self, path, properties):
- logger.debug("persistentGroupAdded: %s %s" % (path, str(properties)))
- self.persistent = path
- def run_test(self, *args):
- logger.debug("run_test")
- params = dbus.Dictionary({'persistent': True,
- 'frequency': 2412})
- logger.info("Add a persistent group")
- p2p.GroupAdd(params)
- return False
- def success(self):
- return True
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- persistent = t.persistent
- p_obj = bus.get_object(WPAS_DBUS_SERVICE, persistent)
- res = p_obj.Get(WPAS_DBUS_PERSISTENT_GROUP, "Properties",
- dbus_interface=dbus.PROPERTIES_IFACE, byte_arrays=True)
- logger.info("Persistent group Properties: " + str(res))
- vals = dbus.Dictionary({ 'ssid': 'DIRECT-foo' }, signature='sv')
- p_obj.Set(WPAS_DBUS_PERSISTENT_GROUP, "Properties", vals,
- dbus_interface=dbus.PROPERTIES_IFACE)
- res2 = p_obj.Get(WPAS_DBUS_PERSISTENT_GROUP, "Properties",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(res) != len(res2):
- raise Exception("Different number of parameters")
- for k in res:
- if k != 'ssid' and res[k] != res2[k]:
- raise Exception("Parameter %s value changes" % k)
- if res2['ssid'] != '"DIRECT-foo"':
- raise Exception("Unexpected ssid")
- args = dbus.Dictionary({ 'ssid': 'DIRECT-testing',
- 'psk': '1234567890' }, signature='sv')
- group = p2p.AddPersistentGroup(args)
- groups = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "PersistentGroups",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(groups) != 2:
- raise Exception("Unexpected number of persistent groups: " + str(groups))
- p2p.RemoveAllPersistentGroups()
- groups = if_obj.Get(WPAS_DBUS_IFACE_P2PDEVICE, "PersistentGroups",
- dbus_interface=dbus.PROPERTIES_IFACE)
- if len(groups) != 0:
- raise Exception("Unexpected number of persistent groups: " + str(groups))
- try:
- p2p.RemovePersistentGroup(persistent)
- raise Exception("Invalid RemovePersistentGroup accepted")
- except dbus.exceptions.DBusException, e:
- if "NetworkUnknown: There is no such persistent group" not in str(e):
- raise Exception("Unexpected error message for invalid RemovePersistentGroup: " + str(e))
- def test_dbus_p2p_reinvoke_persistent(dev, apdev):
- """D-Bus P2P reinvoke persistent group"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.first = True
- self.waiting_end = False
- self.done = False
- self.invited = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.persistentGroupAdded,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "PersistentGroupAdded")
- self.add_signal(self.provisionDiscoveryRequestDisplayPin,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "ProvisionDiscoveryRequestDisplayPin")
- self.add_signal(self.staAuthorized, WPAS_DBUS_IFACE,
- "StaAuthorized")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- if not self.invited:
- g_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['group_object'])
- res = g_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- bssid = ':'.join([binascii.hexlify(l) for l in res['BSSID']])
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.scan_for_bss(bssid, freq=2412)
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 join")
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- if self.invited:
- self.done = True
- self.loop.quit()
- else:
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.global_request("SET persistent_reconnect 1")
- dev1.p2p_listen()
- args = { 'persistent_group_object': dbus.ObjectPath(path),
- 'peer': self.peer_path }
- try:
- pin = p2p.Invite(args)
- raise Exception("Invalid Invite accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Invite: " + str(e))
- args = { 'persistent_group_object': self.persistent,
- 'peer': self.peer_path }
- pin = p2p.Invite(args)
- self.invited = True
- self.sta_group_ev = dev1.wait_global_event(["P2P-GROUP-STARTED"],
- timeout=15)
- if self.sta_group_ev is None:
- raise Exception("P2P-GROUP-STARTED event not seen")
- def persistentGroupAdded(self, path, properties):
- logger.debug("persistentGroupAdded: %s %s" % (path, str(properties)))
- self.persistent = path
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- peer_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
- self.peer = peer_obj.GetAll(WPAS_DBUS_P2P_PEER,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- def provisionDiscoveryRequestDisplayPin(self, peer_object, pin):
- logger.debug("provisionDiscoveryRequestDisplayPin - peer=%s pin=%s" % (peer_object, pin))
- self.peer_path = peer_object
- peer = binascii.unhexlify(peer_object.split('/')[-1])
- addr = ""
- for p in peer:
- if len(addr) > 0:
- addr += ':'
- addr += '%02x' % ord(p)
- params = { 'Role': 'registrar',
- 'P2PDeviceAddress': self.peer['DeviceAddress'],
- 'Bssid': self.peer['DeviceAddress'],
- 'Type': 'pin',
- 'Pin': '12345670' }
- logger.info("Authorize peer to connect to the group")
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- wps = dbus.Interface(self.g_if_obj, WPAS_DBUS_IFACE_WPS)
- wps.Start(params)
- self.sta_group_ev = dev1.wait_global_event(["P2P-GROUP-STARTED"],
- timeout=15)
- if self.sta_group_ev is None:
- raise Exception("P2P-GROUP-STARTED event not seen")
- def staAuthorized(self, name):
- logger.debug("staAuthorized: " + name)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_form_result(self.sta_group_ev)
- dev1.remove_group()
- ev = dev1.wait_global_event(["P2P-GROUP-REMOVED"], timeout=10)
- if ev is None:
- raise Exception("Group removal timed out")
- group_p2p = dbus.Interface(self.g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def run_test(self, *args):
- logger.debug("run_test")
- params = dbus.Dictionary({'persistent': True,
- 'frequency': 2412})
- logger.info("Add a persistent group")
- p2p.GroupAdd(params)
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_go_neg_rx(dev, apdev):
- """D-Bus P2P GO Negotiation receive"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.goNegotiationRequest,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationRequest",
- byte_arrays=True)
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- def goNegotiationRequest(self, path, dev_passwd_id, go_intent=0):
- logger.debug("goNegotiationRequest: path=%s dev_passwd_id=%d go_intent=%d" % (path, dev_passwd_id, go_intent))
- if dev_passwd_id != 1:
- raise Exception("Unexpected dev_passwd_id=%d" % dev_passwd_id)
- args = { 'peer': path, 'wps_method': 'display', 'pin': '12345670',
- 'go_intent': 15, 'persistent': False, 'frequency': 5175 }
- try:
- p2p.Connect(args)
- raise Exception("Invalid Connect accepted")
- except dbus.exceptions.DBusException, e:
- if "ConnectChannelUnsupported" not in str(e):
- raise Exception("Unexpected error message for invalid Connect: " + str(e))
- args = { 'peer': path, 'wps_method': 'display', 'pin': '12345670',
- 'go_intent': 15, 'persistent': False }
- p2p.Connect(args)
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Listen(10)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- if not dev1.discover_peer(addr0):
- raise Exception("Peer not found")
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 enter")
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_go_neg_auth(dev, apdev):
- """D-Bus P2P GO Negotiation authorized"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.peer_joined = False
- self.peer_disconnected = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.staDeauthorized, WPAS_DBUS_IFACE,
- "StaDeauthorized")
- self.add_signal(self.peerJoined, WPAS_DBUS_GROUP,
- "PeerJoined")
- self.add_signal(self.peerDisconnected, WPAS_DBUS_GROUP,
- "PeerDisconnected")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- args = { 'peer': path, 'wps_method': 'keypad',
- 'go_intent': 15, 'authorize_only': True }
- try:
- p2p.Connect(args)
- raise Exception("Invalid Connect accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e):
- raise Exception("Unexpected error message for invalid Connect: " + str(e))
- args = { 'peer': path, 'wps_method': 'keypad', 'pin': '12345670',
- 'go_intent': 15, 'authorize_only': True }
- p2p.Connect(args)
- p2p.Listen(10)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- if not dev1.discover_peer(addr0):
- raise Exception("Peer not found")
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=0")
- ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Group formation timed out")
- self.sta_group_ev = ev
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_form_result(self.sta_group_ev)
- dev1.remove_group()
- def staDeauthorized(self, name):
- logger.debug("staDeuthorized: " + name)
- group_p2p = dbus.Interface(self.g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- def peerJoined(self, peer):
- logger.debug("peerJoined: " + peer)
- self.peer_joined = True
- def peerDisconnected(self, peer):
- logger.debug("peerDisconnected: " + peer)
- self.peer_disconnected = True
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done and self.peer_joined and self.peer_disconnected
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_go_neg_init(dev, apdev):
- """D-Bus P2P GO Negotiation initiation"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.peer_group_added = False
- self.peer_group_removed = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.propertiesChanged, dbus.PROPERTIES_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- args = { 'peer': path, 'wps_method': 'keypad', 'pin': '12345670',
- 'go_intent': 0 }
- p2p.Connect(args)
- ev = dev1.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
- if ev is None:
- raise Exception("Timeout while waiting for GO Neg Request")
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=15")
- ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Group formation timed out")
- self.sta_group_ev = ev
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- group_p2p = dbus.Interface(g_if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_form_result(self.sta_group_ev)
- dev1.remove_group()
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- def propertiesChanged(self, interface_name, changed_properties,
- invalidated_properties):
- logger.debug("propertiesChanged: interface_name=%s changed_properties=%s invalidated_properties=%s" % (interface_name, str(changed_properties), str(invalidated_properties)))
- if interface_name != WPAS_DBUS_P2P_PEER:
- return
- if "Groups" not in changed_properties:
- return
- if len(changed_properties["Groups"]) > 0:
- self.peer_group_added = True
- if len(changed_properties["Groups"]) == 0:
- self.peer_group_removed = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done and self.peer_group_added and self.peer_group_removed
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_group_termination_by_go(dev, apdev):
- """D-Bus P2P group removal on GO terminating the group"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.peer_group_added = False
- self.peer_group_removed = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.propertiesChanged, dbus.PROPERTIES_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- args = { 'peer': path, 'wps_method': 'keypad', 'pin': '12345670',
- 'go_intent': 0 }
- p2p.Connect(args)
- ev = dev1.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
- if ev is None:
- raise Exception("Timeout while waiting for GO Neg Request")
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=15")
- ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Group formation timed out")
- self.sta_group_ev = ev
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_form_result(self.sta_group_ev)
- dev1.remove_group()
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- def propertiesChanged(self, interface_name, changed_properties,
- invalidated_properties):
- logger.debug("propertiesChanged: interface_name=%s changed_properties=%s invalidated_properties=%s" % (interface_name, str(changed_properties), str(invalidated_properties)))
- if interface_name != WPAS_DBUS_P2P_PEER:
- return
- if "Groups" not in changed_properties:
- return
- if len(changed_properties["Groups"]) > 0:
- self.peer_group_added = True
- if len(changed_properties["Groups"]) == 0 and self.peer_group_added:
- self.peer_group_removed = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done and self.peer_group_added and self.peer_group_removed
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_group_idle_timeout(dev, apdev):
- """D-Bus P2P group removal on idle timeout"""
- try:
- dev[0].global_request("SET p2p_group_idle 1")
- _test_dbus_p2p_group_idle_timeout(dev, apdev)
- finally:
- dev[0].global_request("SET p2p_group_idle 0")
- def _test_dbus_p2p_group_idle_timeout(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- dev[1].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.group_started = False
- self.peer_group_added = False
- self.peer_group_removed = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.propertiesChanged, dbus.PROPERTIES_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- args = { 'peer': path, 'wps_method': 'keypad', 'pin': '12345670',
- 'go_intent': 0 }
- p2p.Connect(args)
- ev = dev1.wait_global_event(["P2P-GO-NEG-REQUEST"], timeout=15)
- if ev is None:
- raise Exception("Timeout while waiting for GO Neg Request")
- dev1.global_request("P2P_CONNECT " + addr0 + " 12345670 display go_intent=15")
- ev = dev1.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Group formation timed out")
- self.sta_group_ev = ev
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.group_started = True
- g_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['interface_object'])
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_form_result(self.sta_group_ev)
- ifaddr = dev1.group_request("STA-FIRST").splitlines()[0]
- # Force disassociation with different reason code so that the
- # P2P Client using D-Bus does not get normal group termination event
- # from the GO.
- dev1.group_request("DEAUTHENTICATE " + ifaddr + " reason=0 test=0")
- dev1.remove_group()
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- self.done = True
- def propertiesChanged(self, interface_name, changed_properties,
- invalidated_properties):
- logger.debug("propertiesChanged: interface_name=%s changed_properties=%s invalidated_properties=%s" % (interface_name, str(changed_properties), str(invalidated_properties)))
- if interface_name != WPAS_DBUS_P2P_PEER:
- return
- if not self.group_started:
- return
- if "Groups" not in changed_properties:
- return
- if len(changed_properties["Groups"]) > 0:
- self.peer_group_added = True
- if len(changed_properties["Groups"]) == 0:
- self.peer_group_removed = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done and self.peer_group_added and self.peer_group_removed
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_wps_failure(dev, apdev):
- """D-Bus P2P WPS failure"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- addr0 = dev[0].p2p_dev_addr()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.wps_failed = False
- self.formation_failure = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.goNegotiationRequest,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationRequest",
- byte_arrays=True)
- self.add_signal(self.goNegotiationSuccess,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GONegotiationSuccess",
- byte_arrays=True)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.wpsFailed, WPAS_DBUS_IFACE_P2PDEVICE,
- "WpsFailed")
- self.add_signal(self.groupFormationFailure,
- WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFormationFailure")
- self.loop.run()
- return self
- def goNegotiationRequest(self, path, dev_passwd_id, go_intent=0):
- logger.debug("goNegotiationRequest: path=%s dev_passwd_id=%d go_intent=%d" % (path, dev_passwd_id, go_intent))
- if dev_passwd_id != 1:
- raise Exception("Unexpected dev_passwd_id=%d" % dev_passwd_id)
- args = { 'peer': path, 'wps_method': 'display', 'pin': '12345670',
- 'go_intent': 15 }
- p2p.Connect(args)
- def goNegotiationSuccess(self, properties):
- logger.debug("goNegotiationSuccess: properties=%s" % str(properties))
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- raise Exception("Unexpected GroupStarted")
- def wpsFailed(self, name, args):
- logger.debug("wpsFailed - name=%s args=%s" % (name, str(args)))
- self.wps_failed = True
- if self.formation_failure:
- self.loop.quit()
- def groupFormationFailure(self, reason):
- logger.debug("groupFormationFailure - reason=%s" % reason)
- self.formation_failure = True
- if self.wps_failed:
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Listen(10)
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- if not dev1.discover_peer(addr0):
- raise Exception("Peer not found")
- dev1.global_request("P2P_CONNECT " + addr0 + " 87654321 enter")
- return False
- def success(self):
- return self.wps_failed and self.formation_failure
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_two_groups(dev, apdev):
- """D-Bus P2P with two concurrent groups"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- dev[0].request("SET p2p_no_group_iface 0")
- addr0 = dev[0].p2p_dev_addr()
- addr1 = dev[1].p2p_dev_addr()
- addr2 = dev[2].p2p_dev_addr()
- dev[1].p2p_start_go(freq=2412)
- dev1_group_ifname = dev[1].group_ifname
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- self.peer = None
- self.go = None
- self.group1 = None
- self.group2 = None
- self.groups_removed = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, dbus.PROPERTIES_IFACE,
- "PropertiesChanged", byte_arrays=True)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.add_signal(self.groupFinished, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupFinished")
- self.add_signal(self.peerJoined, WPAS_DBUS_GROUP,
- "PeerJoined")
- self.loop.run()
- return self
- def propertiesChanged(self, interface_name, changed_properties,
- invalidated_properties):
- logger.debug("propertiesChanged: interface_name=%s changed_properties=%s invalidated_properties=%s" % (interface_name, str(changed_properties), str(invalidated_properties)))
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- if addr2.replace(':','') in path:
- self.peer = path
- elif addr1.replace(':','') in path:
- self.go = path
- if self.go and not self.group1:
- logger.info("Join the group")
- p2p.StopFind()
- pin = '12345670'
- dev1 = WpaSupplicant('wlan1', '/tmp/wpas-wlan1')
- dev1.group_ifname = dev1_group_ifname
- dev1.group_request("WPS_PIN any " + pin)
- args = { 'peer': self.go,
- 'join': True,
- 'wps_method': 'pin',
- 'pin': pin,
- 'frequency': 2412 }
- p2p.Connect(args)
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- prop = if_obj.GetAll(WPAS_DBUS_IFACE_P2PDEVICE,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("p2pdevice properties: " + str(prop))
- g_obj = bus.get_object(WPAS_DBUS_SERVICE,
- properties['group_object'])
- res = g_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.debug("Group properties: " + str(res))
- if not self.group1:
- self.group1 = properties['group_object']
- self.group1iface = properties['interface_object']
- self.g1_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- self.group1iface)
- logger.info("Start autonomous GO")
- params = dbus.Dictionary({ 'frequency': 2412 })
- p2p.GroupAdd(params)
- elif not self.group2:
- self.group2 = properties['group_object']
- self.group2iface = properties['interface_object']
- self.g2_if_obj = bus.get_object(WPAS_DBUS_SERVICE,
- self.group2iface)
- self.g2_bssid = res['BSSID']
- if self.group1 and self.group2:
- logger.info("Authorize peer to join the group")
- a2 = binascii.unhexlify(addr2.replace(':',''))
- params = { 'Role': 'enrollee',
- 'P2PDeviceAddress': dbus.ByteArray(a2),
- 'Bssid': dbus.ByteArray(a2),
- 'Type': 'pin',
- 'Pin': '12345670' }
- g_wps = dbus.Interface(self.g2_if_obj, WPAS_DBUS_IFACE_WPS)
- g_wps.Start(params)
- bssid = ':'.join([binascii.hexlify(l) for l in self.g2_bssid])
- dev2 = WpaSupplicant('wlan2', '/tmp/wpas-wlan2')
- dev2.scan_for_bss(bssid, freq=2412)
- dev2.global_request("P2P_CONNECT " + bssid + " 12345670 join freq=2412")
- ev = dev2.wait_global_event(["P2P-GROUP-STARTED"], timeout=15)
- if ev is None:
- raise Exception("Group join timed out")
- self.dev2_group_ev = ev
- def groupFinished(self, properties):
- logger.debug("groupFinished: " + str(properties))
- if self.group1 == properties['group_object']:
- self.group1 = None
- elif self.group2 == properties['group_object']:
- self.group2 = None
- if not self.group1 and not self.group2:
- self.done = True
- self.loop.quit()
- def peerJoined(self, peer):
- logger.debug("peerJoined: " + peer)
- if self.groups_removed:
- return
- self.check_results()
- dev2 = WpaSupplicant('wlan2', '/tmp/wpas-wlan2')
- dev2.group_form_result(self.dev2_group_ev)
- dev2.remove_group()
- logger.info("Disconnect group2")
- group_p2p = dbus.Interface(self.g2_if_obj,
- WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- logger.info("Disconnect group1")
- group_p2p = dbus.Interface(self.g1_if_obj,
- WPAS_DBUS_IFACE_P2PDEVICE)
- group_p2p.Disconnect()
- self.groups_removed = True
- def check_results(self):
- logger.info("Check results with two concurrent groups in operation")
- g1_obj = bus.get_object(WPAS_DBUS_SERVICE, self.group1)
- res1 = g1_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- g2_obj = bus.get_object(WPAS_DBUS_SERVICE, self.group2)
- res2 = g2_obj.GetAll(WPAS_DBUS_GROUP,
- dbus_interface=dbus.PROPERTIES_IFACE,
- byte_arrays=True)
- logger.info("group1 = " + self.group1)
- logger.debug("Group properties: " + str(res1))
- logger.info("group2 = " + self.group2)
- logger.debug("Group properties: " + str(res2))
- prop = if_obj.GetAll(WPAS_DBUS_IFACE_P2PDEVICE,
- dbus_interface=dbus.PROPERTIES_IFACE)
- logger.debug("p2pdevice properties: " + str(prop))
- if res1['Role'] != 'client':
- raise Exception("Group1 role reported incorrectly: " + res1['Role'])
- if res2['Role'] != 'GO':
- raise Exception("Group2 role reported incorrectly: " + res2['Role'])
- if prop['Role'] != 'device':
- raise Exception("p2pdevice role reported incorrectly: " + prop['Role'])
- if len(res2['Members']) != 1:
- raise Exception("Unexpected Members value for group 2")
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].remove_group()
- def test_dbus_p2p_cancel(dev, apdev):
- """D-Bus P2P Cancel"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- try:
- p2p.Cancel()
- raise Exception("Unexpected p2p.Cancel() success")
- except dbus.exceptions.DBusException, e:
- pass
- addr0 = dev[0].p2p_dev_addr()
- dev[1].p2p_listen()
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.deviceFound, WPAS_DBUS_IFACE_P2PDEVICE,
- "DeviceFound")
- self.loop.run()
- return self
- def deviceFound(self, path):
- logger.debug("deviceFound: path=%s" % path)
- args = { 'peer': path, 'wps_method': 'keypad', 'pin': '12345670',
- 'go_intent': 0 }
- p2p.Connect(args)
- p2p.Cancel()
- self.done = True
- self.loop.quit()
- def run_test(self, *args):
- logger.debug("run_test")
- p2p.Find(dbus.Dictionary({'DiscoveryType': 'social'}))
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_p2p_ip_addr(dev, apdev):
- """D-Bus P2P and IP address parameters"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- p2p = dbus.Interface(if_obj, WPAS_DBUS_IFACE_P2PDEVICE)
- vals = [ ("IpAddrGo", "192.168.43.1"),
- ("IpAddrMask", "255.255.255.0"),
- ("IpAddrStart", "192.168.43.100"),
- ("IpAddrEnd", "192.168.43.199") ]
- for field, value in vals:
- if_obj.Set(WPAS_DBUS_IFACE, field, value,
- dbus_interface=dbus.PROPERTIES_IFACE)
- val = if_obj.Get(WPAS_DBUS_IFACE, field,
- dbus_interface=dbus.PROPERTIES_IFACE)
- if val != value:
- raise Exception("Unexpected %s value: %s" % (field, val))
- set_ip_addr_info(dev[1])
- dev[0].global_request("SET p2p_go_intent 0")
- req = dev[0].global_request("NFC_GET_HANDOVER_REQ NDEF P2P-CR").rstrip()
- if "FAIL" in req:
- raise Exception("Failed to generate NFC connection handover request")
- sel = dev[1].global_request("NFC_GET_HANDOVER_SEL NDEF P2P-CR").rstrip()
- if "FAIL" in sel:
- raise Exception("Failed to generate NFC connection handover select")
- dev[0].dump_monitor()
- dev[1].dump_monitor()
- res = dev[1].global_request("NFC_REPORT_HANDOVER RESP P2P " + req + " " + sel)
- if "FAIL" in res:
- raise Exception("Failed to report NFC connection handover to wpa_supplicant(resp)")
- res = dev[0].global_request("NFC_REPORT_HANDOVER INIT P2P " + req + " " + sel)
- if "FAIL" in res:
- raise Exception("Failed to report NFC connection handover to wpa_supplicant(init)")
- class TestDbusP2p(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_test)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.groupStarted, WPAS_DBUS_IFACE_P2PDEVICE,
- "GroupStarted")
- self.loop.run()
- return self
- def groupStarted(self, properties):
- logger.debug("groupStarted: " + str(properties))
- self.loop.quit()
- if 'IpAddrGo' not in properties:
- logger.info("IpAddrGo missing from GroupStarted")
- ip_addr_go = properties['IpAddrGo']
- addr = "%d.%d.%d.%d" % (ip_addr_go[0], ip_addr_go[1], ip_addr_go[2], ip_addr_go[3])
- if addr != "192.168.42.1":
- logger.info("Unexpected IpAddrGo value: " + addr)
- self.done = True
- def run_test(self, *args):
- logger.debug("run_test")
- return False
- def success(self):
- return self.done
- with TestDbusP2p(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_introspect(dev, apdev):
- """D-Bus introspection"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- res = if_obj.Introspect(WPAS_DBUS_IFACE,
- dbus_interface=dbus.INTROSPECTABLE_IFACE)
- logger.info("Initial Introspect: " + str(res))
- if res is None or "Introspectable" not in res or "GroupStarted" not in res:
- raise Exception("Unexpected initial Introspect response: " + str(res))
- if "FastReauth" not in res or "PassiveScan" not in res:
- raise Exception("Unexpected initial Introspect response: " + str(res))
- with alloc_fail(dev[0], 1, "wpa_dbus_introspect"):
- res2 = if_obj.Introspect(WPAS_DBUS_IFACE,
- dbus_interface=dbus.INTROSPECTABLE_IFACE)
- logger.info("Introspect: " + str(res2))
- if res2 is not None:
- raise Exception("Unexpected Introspect response")
- with alloc_fail(dev[0], 1, "=add_interface;wpa_dbus_introspect"):
- res2 = if_obj.Introspect(WPAS_DBUS_IFACE,
- dbus_interface=dbus.INTROSPECTABLE_IFACE)
- logger.info("Introspect: " + str(res2))
- if res2 is None:
- raise Exception("No Introspect response")
- if len(res2) >= len(res):
- raise Exception("Unexpected Introspect response")
- with alloc_fail(dev[0], 1, "wpabuf_alloc;add_interface;wpa_dbus_introspect"):
- res2 = if_obj.Introspect(WPAS_DBUS_IFACE,
- dbus_interface=dbus.INTROSPECTABLE_IFACE)
- logger.info("Introspect: " + str(res2))
- if res2 is None:
- raise Exception("No Introspect response")
- if len(res2) >= len(res):
- raise Exception("Unexpected Introspect response")
- with alloc_fail(dev[0], 2, "=add_interface;wpa_dbus_introspect"):
- res2 = if_obj.Introspect(WPAS_DBUS_IFACE,
- dbus_interface=dbus.INTROSPECTABLE_IFACE)
- logger.info("Introspect: " + str(res2))
- if res2 is None:
- raise Exception("No Introspect response")
- if len(res2) >= len(res):
- raise Exception("Unexpected Introspect response")
- def test_dbus_ap(dev, apdev):
- """D-Bus AddNetwork for AP mode"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "test-wpa2-psk"
- passphrase = 'qwertyuiop'
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.started = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.networkAdded, WPAS_DBUS_IFACE, "NetworkAdded")
- self.add_signal(self.networkSelected, WPAS_DBUS_IFACE,
- "NetworkSelected")
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def networkAdded(self, network, properties):
- logger.debug("networkAdded: %s" % str(network))
- logger.debug(str(properties))
- def networkSelected(self, network):
- logger.debug("networkSelected: %s" % str(network))
- self.network_selected = True
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- self.started = True
- self.loop.quit()
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'WPA-PSK',
- 'psk': passphrase,
- 'mode': 2,
- 'frequency': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- return self.started
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- dev[1].connect(ssid, psk=passphrase, scan_freq="2412")
- def test_dbus_connect_wpa_eap(dev, apdev):
- """D-Bus AddNetwork and connection with WPA+WPA2-Enterprise AP"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "test-wpa-eap"
- params = hostapd.wpa_eap_params(ssid=ssid)
- params["wpa"] = "3"
- params["rsn_pairwise"] = "CCMP"
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.done = False
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.add_signal(self.eap, WPAS_DBUS_IFACE, "EAP")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'State' in properties and properties['State'] == "completed":
- self.done = True
- self.loop.quit()
- def eap(self, status, parameter):
- logger.debug("EAP: status=%s parameter=%s" % (status, parameter))
- def run_connect(self, *args):
- logger.debug("run_connect")
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'WPA-EAP',
- 'eap': 'PEAP',
- 'identity': 'user',
- 'password': 'password',
- 'ca_cert': 'auth_serv/ca.pem',
- 'phase2': 'auth=MSCHAPV2',
- 'scan_freq': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- return self.done
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
- def test_dbus_ap_scan_2_ap_mode_scan(dev, apdev):
- """AP_SCAN 2 AP mode and D-Bus Scan()"""
- try:
- _test_dbus_ap_scan_2_ap_mode_scan(dev, apdev)
- finally:
- dev[0].request("AP_SCAN 1")
- def _test_dbus_ap_scan_2_ap_mode_scan(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- if "OK" not in dev[0].request("AP_SCAN 2"):
- raise Exception("Failed to set AP_SCAN 2")
- id = dev[0].add_network()
- dev[0].set_network(id, "mode", "2")
- dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
- dev[0].set_network(id, "key_mgmt", "NONE")
- dev[0].set_network(id, "frequency", "2412")
- dev[0].set_network(id, "scan_freq", "2412")
- dev[0].set_network(id, "disabled", "0")
- dev[0].select_network(id)
- ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5)
- if ev is None:
- raise Exception("AP failed to start")
- with fail_test(dev[0], 1, "wpa_driver_nl80211_scan"):
- iface.Scan({'Type': 'active',
- 'AllowRoam': True,
- 'Channels': [(dbus.UInt32(2412), dbus.UInt32(20))]})
- ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
- "AP-DISABLED"], timeout=5)
- if ev is None:
- raise Exception("CTRL-EVENT-SCAN-FAILED not seen")
- if "AP-DISABLED" in ev:
- raise Exception("Unexpected AP-DISABLED event")
- if "retry=1" in ev:
- # Wait for the retry to scan happen
- ev = dev[0].wait_event(["CTRL-EVENT-SCAN-FAILED",
- "AP-DISABLED"], timeout=5)
- if ev is None:
- raise Exception("CTRL-EVENT-SCAN-FAILED not seen - retry")
- if "AP-DISABLED" in ev:
- raise Exception("Unexpected AP-DISABLED event - retry")
- dev[1].connect("wpas-ap-open", key_mgmt="NONE", scan_freq="2412")
- dev[1].request("DISCONNECT")
- dev[1].wait_disconnected()
- dev[0].request("DISCONNECT")
- dev[0].wait_disconnected()
- def test_dbus_expectdisconnect(dev, apdev):
- """D-Bus ExpectDisconnect"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- wpas = dbus.Interface(wpas_obj, WPAS_DBUS_SERVICE)
- params = { "ssid": "test-open" }
- hapd = hostapd.add_ap(apdev[0], params)
- dev[0].connect("test-open", key_mgmt="NONE", scan_freq="2412")
- # This does not really verify the behavior other than by going through the
- # code path for additional coverage.
- wpas.ExpectDisconnect()
- dev[0].request("DISCONNECT")
- dev[0].wait_disconnected()
- def test_dbus_save_config(dev, apdev):
- """D-Bus SaveConfig"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- try:
- iface.SaveConfig()
- raise Exception("SaveConfig() accepted unexpectedly")
- except dbus.exceptions.DBusException, e:
- if not str(e).startswith("fi.w1.wpa_supplicant1.UnknownError: Not allowed to update configuration"):
- raise Exception("Unexpected error message for SaveConfig(): " + str(e))
- def test_dbus_vendor_elem(dev, apdev):
- """D-Bus vendor element operations"""
- try:
- _test_dbus_vendor_elem(dev, apdev)
- finally:
- dev[0].request("VENDOR_ELEM_REMOVE 1 *")
- def _test_dbus_vendor_elem(dev, apdev):
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- dev[0].request("VENDOR_ELEM_REMOVE 1 *")
- try:
- ie = dbus.ByteArray("\x00\x00")
- iface.VendorElemAdd(-1, ie)
- raise Exception("Invalid VendorElemAdd() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Invalid ID" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemAdd[1]: " + str(e))
- try:
- ie = dbus.ByteArray("")
- iface.VendorElemAdd(1, ie)
- raise Exception("Invalid VendorElemAdd() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Invalid value" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemAdd[2]: " + str(e))
- try:
- ie = dbus.ByteArray("\x00\x01")
- iface.VendorElemAdd(1, ie)
- raise Exception("Invalid VendorElemAdd() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Parse error" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemAdd[3]: " + str(e))
- try:
- iface.VendorElemGet(-1)
- raise Exception("Invalid VendorElemGet() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Invalid ID" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemGet[1]: " + str(e))
- try:
- iface.VendorElemGet(1)
- raise Exception("Invalid VendorElemGet() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "ID value does not exist" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemGet[2]: " + str(e))
- try:
- ie = dbus.ByteArray("\x00\x00")
- iface.VendorElemRem(-1, ie)
- raise Exception("Invalid VendorElemRemove() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Invalid ID" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemRemove[1]: " + str(e))
- try:
- ie = dbus.ByteArray("")
- iface.VendorElemRem(1, ie)
- raise Exception("Invalid VendorElemRemove() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Invalid value" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemRemove[1]: " + str(e))
- iface.VendorElemRem(1, "*")
- ie = dbus.ByteArray("\x00\x01\x00")
- iface.VendorElemAdd(1, ie)
- val = iface.VendorElemGet(1)
- if len(val) != len(ie):
- raise Exception("Unexpected VendorElemGet length")
- for i in range(len(val)):
- if val[i] != dbus.Byte(ie[i]):
- raise Exception("Unexpected VendorElemGet data")
- ie2 = dbus.ByteArray("\xe0\x00")
- iface.VendorElemAdd(1, ie2)
- ies = ie + ie2
- val = iface.VendorElemGet(1)
- if len(val) != len(ies):
- raise Exception("Unexpected VendorElemGet length[2]")
- for i in range(len(val)):
- if val[i] != dbus.Byte(ies[i]):
- raise Exception("Unexpected VendorElemGet data[2]")
- try:
- test_ie = dbus.ByteArray("\x01\x01")
- iface.VendorElemRem(1, test_ie)
- raise Exception("Invalid VendorElemRemove() accepted")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "Parse error" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemRemove[1]: " + str(e))
- iface.VendorElemRem(1, ie)
- val = iface.VendorElemGet(1)
- if len(val) != len(ie2):
- raise Exception("Unexpected VendorElemGet length[3]")
- iface.VendorElemRem(1, "*")
- try:
- iface.VendorElemGet(1)
- raise Exception("Invalid VendorElemGet() accepted after removal")
- except dbus.exceptions.DBusException, e:
- if "InvalidArgs" not in str(e) or "ID value does not exist" not in str(e):
- raise Exception("Unexpected error message for invalid VendorElemGet after removal: " + str(e))
- def test_dbus_assoc_reject(dev, apdev):
- """D-Bus AssocStatusCode"""
- (bus,wpas_obj,path,if_obj) = prepare_dbus(dev[0])
- iface = dbus.Interface(if_obj, WPAS_DBUS_IFACE)
- ssid = "test-open"
- params = { "ssid": ssid,
- "max_listen_interval": "1" }
- hapd = hostapd.add_ap(apdev[0], params)
- class TestDbusConnect(TestDbus):
- def __init__(self, bus):
- TestDbus.__init__(self, bus)
- self.assoc_status_seen = False
- self.state = 0
- def __enter__(self):
- gobject.timeout_add(1, self.run_connect)
- gobject.timeout_add(15000, self.timeout)
- self.add_signal(self.propertiesChanged, WPAS_DBUS_IFACE,
- "PropertiesChanged")
- self.loop.run()
- return self
- def propertiesChanged(self, properties):
- logger.debug("propertiesChanged: %s" % str(properties))
- if 'AssocStatusCode' in properties:
- status = properties['AssocStatusCode']
- if status != 51:
- logger.info("Unexpected status code: " + str(status))
- else:
- self.assoc_status_seen = True
- iface.Disconnect()
- self.loop.quit()
- def run_connect(self, *args):
- args = dbus.Dictionary({ 'ssid': ssid,
- 'key_mgmt': 'NONE',
- 'scan_freq': 2412 },
- signature='sv')
- self.netw = iface.AddNetwork(args)
- iface.SelectNetwork(self.netw)
- return False
- def success(self):
- return self.assoc_status_seen
- with TestDbusConnect(bus) as t:
- if not t.success():
- raise Exception("Expected signals not seen")
|