diff --git a/Cargo.lock b/Cargo.lock index bd3a6f7ab..316ed73a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -477,7 +477,7 @@ dependencies = [ [[package]] name = "com_rs" version = "0.1.0" -source = "git+https://github.com/betrusted-io/com_rs.git?rev=1effb7eaebbec59f7fda4a678e2d36efafc2e673#1effb7eaebbec59f7fda4a678e2d36efafc2e673" +source = "git+https://github.com/betrusted-io/com_rs.git?rev=7df87fd4914eb3d2f74bf630aa0b828123368fce#7df87fd4914eb3d2f74bf630aa0b828123368fce" [[package]] name = "com_rs-ref" @@ -1355,8 +1355,10 @@ dependencies = [ "com", "com_rs-ref", "llio", + "locales", "log", "log-server", + "modals", "num-derive", "num-traits", "pddb", diff --git a/imports/com_rs-ref/Cargo.toml b/imports/com_rs-ref/Cargo.toml index 9ec1a9303..080d7dc07 100644 --- a/imports/com_rs-ref/Cargo.toml +++ b/imports/com_rs-ref/Cargo.toml @@ -7,7 +7,7 @@ description = "com_rs import package" # Dependency policy: fully specify dependencies to the minor version number [dependencies] -com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "1effb7eaebbec59f7fda4a678e2d36efafc2e673" } +com_rs = { git = "https://github.com/betrusted-io/com_rs.git", rev = "7df87fd4914eb3d2f74bf630aa0b828123368fce" } #com_rs = { path = "../../../betrusted-ec/sw/com_rs" } diff --git a/precursors/rom.db b/precursors/rom.db index 7de5b207e..fa01b8874 100644 --- a/precursors/rom.db +++ b/precursors/rom.db @@ -1,128 +1,128 @@ -KEYROM 0 A SLICE_X36Y50 b'47d7d04f30d09e62' -KEYROM 0 B SLICE_X36Y50 b'14fda731841da875' -KEYROM 0 C SLICE_X36Y50 b'68d4802ae4d74f35' -KEYROM 0 D SLICE_X36Y50 b'ad6e1210f30f9218' -KEYROM 1 A SLICE_X37Y50 b'a4dffd90976b0b4a' -KEYROM 1 B SLICE_X37Y50 b'901c071ee742477d' -KEYROM 1 C SLICE_X37Y50 b'1f36196673b9f51f' -KEYROM 1 D SLICE_X37Y50 b'34bba10e037bc532' -KEYROM 2 A SLICE_X36Y51 b'a748053fea72ac55' -KEYROM 2 B SLICE_X36Y51 b'9b9d741846461b4e' -KEYROM 2 C SLICE_X36Y51 b'1ee201e75fe5b9b0' -KEYROM 2 D SLICE_X36Y51 b'9aacbfa2672262fc' -KEYROM 3 A SLICE_X37Y51 b'5119fb18a95c0b8d' -KEYROM 3 B SLICE_X37Y51 b'2dd2d6336eef1ba6' -KEYROM 3 C SLICE_X37Y51 b'fedf8e805160529a' -KEYROM 3 D SLICE_X37Y51 b'6284d91b0390d36a' -KEYROM 4 A SLICE_X36Y52 b'8a89c5b6cb2ee6e6' -KEYROM 4 B SLICE_X36Y52 b'ce64cb8480440d06' -KEYROM 4 C SLICE_X36Y52 b'bcbec5aaba5859d2' -KEYROM 4 D SLICE_X36Y52 b'a5b989c1f9f063bb' -KEYROM 5 A SLICE_X37Y52 b'9e39b7bc3b770527' -KEYROM 5 B SLICE_X37Y52 b'84f1803776c7a384' -KEYROM 5 C SLICE_X37Y52 b'2e519aa0d9ce7a1d' -KEYROM 5 D SLICE_X37Y52 b'1b811618014866f6' -KEYROM 6 A SLICE_X36Y53 b'f838e9aa8611f2c6' -KEYROM 6 B SLICE_X36Y53 b'f3cd064ebc52de12' -KEYROM 6 C SLICE_X36Y53 b'0ae835f2d0e5076d' -KEYROM 6 D SLICE_X36Y53 b'5d3ce296d419d003' -KEYROM 7 A SLICE_X37Y53 b'257b5ba18e2ddba7' -KEYROM 7 B SLICE_X37Y53 b'0e1e87b69424b201' -KEYROM 7 C SLICE_X37Y53 b'f8b3d528f9885418' -KEYROM 7 D SLICE_X37Y53 b'ea19ed62eef2e69e' -KEYROM 8 A SLICE_X36Y54 b'3612ab28f9f7e72d' -KEYROM 8 B SLICE_X36Y54 b'41f5d1a93abd2c93' -KEYROM 8 C SLICE_X36Y54 b'57d4ec4f22c226ba' -KEYROM 8 D SLICE_X36Y54 b'3f7188ea25f2d077' -KEYROM 9 A SLICE_X37Y54 b'3f51a3f9b9932ed4' -KEYROM 9 B SLICE_X37Y54 b'cf0e73bd27bca778' -KEYROM 9 C SLICE_X37Y54 b'd3373e50bd4cb91f' -KEYROM 9 D SLICE_X37Y54 b'e97dffdac39d335e' -KEYROM 10 A SLICE_X36Y55 b'b767ce10e4ee0b7a' -KEYROM 10 B SLICE_X36Y55 b'05196c12f5a773ab' -KEYROM 10 C SLICE_X36Y55 b'd26972fd8ac0a5f8' -KEYROM 10 D SLICE_X36Y55 b'1f4955406840d05f' -KEYROM 11 A SLICE_X37Y55 b'05fe4ca650220c3b' -KEYROM 11 B SLICE_X37Y55 b'c3452b58ffc60b88' -KEYROM 11 C SLICE_X37Y55 b'a9f980745c4a83b1' -KEYROM 11 D SLICE_X37Y55 b'33bdfda8519f8e37' -KEYROM 12 A SLICE_X36Y56 b'133c8a3578a6f37f' -KEYROM 12 B SLICE_X36Y56 b'a35683cb8405a9ec' -KEYROM 12 C SLICE_X36Y56 b'b6971f8a1c866f12' -KEYROM 12 D SLICE_X36Y56 b'61c2581266e48034' -KEYROM 13 A SLICE_X37Y56 b'8dbc0aea56a26650' -KEYROM 13 B SLICE_X37Y56 b'b852dc036e5b70f7' -KEYROM 13 C SLICE_X37Y56 b'1ae1235023b66a89' -KEYROM 13 D SLICE_X37Y56 b'f014ef0ef32b9c66' -KEYROM 14 A SLICE_X36Y57 b'dc9c4d40f0d9377a' -KEYROM 14 B SLICE_X36Y57 b'4fe02d34a2905db7' -KEYROM 14 C SLICE_X36Y57 b'8d807e6faf6e9a6f' -KEYROM 14 D SLICE_X36Y57 b'55e767efbdb73f81' -KEYROM 15 A SLICE_X37Y57 b'7dc01ee818e8e58b' -KEYROM 15 B SLICE_X37Y57 b'1a0b8a7a002ef5fe' -KEYROM 15 C SLICE_X37Y57 b'61524ae7d09b16f5' -KEYROM 15 D SLICE_X37Y57 b'b4577f9253f1a74d' -KEYROM 16 A SLICE_X36Y58 b'08568d97ab55e076' -KEYROM 16 B SLICE_X36Y58 b'1b440c9f9fd48e86' -KEYROM 16 C SLICE_X36Y58 b'7aa894b57c231700' -KEYROM 16 D SLICE_X36Y58 b'3a36cd620aa66a3e' -KEYROM 17 A SLICE_X37Y58 b'c1a2bbd655c5e4f7' -KEYROM 17 B SLICE_X37Y58 b'a58c6303ed034937' -KEYROM 17 C SLICE_X37Y58 b'906cb0941b4552ab' -KEYROM 17 D SLICE_X37Y58 b'997dece6ccc10bb9' -KEYROM 18 A SLICE_X36Y59 b'b519c305160be1fd' -KEYROM 18 B SLICE_X36Y59 b'17950d723e40a682' -KEYROM 18 C SLICE_X36Y59 b'52e1ce9bf2b36dcc' -KEYROM 18 D SLICE_X36Y59 b'e42f70990c358ac7' -KEYROM 19 A SLICE_X37Y59 b'bf6dbda2c56c55c3' -KEYROM 19 B SLICE_X37Y59 b'f0d3bcf12f58da52' -KEYROM 19 C SLICE_X37Y59 b'51f1ee05f89f3570' -KEYROM 19 D SLICE_X37Y59 b'4f4ff3e9c51348d8' -KEYROM 20 A SLICE_X36Y60 b'82262e60459bc706' -KEYROM 20 B SLICE_X36Y60 b'9a1baae63686f7ea' -KEYROM 20 C SLICE_X36Y60 b'bc465cbc1c5715e1' -KEYROM 20 D SLICE_X36Y60 b'45138ed1f2ed4c43' -KEYROM 21 A SLICE_X37Y60 b'86a41e5d9f94e80c' -KEYROM 21 B SLICE_X37Y60 b'6941ee6ed4d6fda1' -KEYROM 21 C SLICE_X37Y60 b'32128f74815de1be' -KEYROM 21 D SLICE_X37Y60 b'688a3860b9412488' -KEYROM 22 A SLICE_X36Y61 b'868b325d84869ad2' -KEYROM 22 B SLICE_X36Y61 b'6558bf931f9a6ac2' -KEYROM 22 C SLICE_X36Y61 b'f7c515ce5f4ad63b' -KEYROM 22 D SLICE_X36Y61 b'8a93f34fb7558c9f' -KEYROM 23 A SLICE_X37Y61 b'292856a114c7b9de' -KEYROM 23 B SLICE_X37Y61 b'ab5b3ecb2ed34f69' -KEYROM 23 C SLICE_X37Y61 b'44b8ba9b543ee491' -KEYROM 23 D SLICE_X37Y61 b'68a132a8735cf43d' -KEYROM 24 A SLICE_X36Y62 b'3474cb1406cd4194' -KEYROM 24 B SLICE_X36Y62 b'1a7eecd6b651283b' -KEYROM 24 C SLICE_X36Y62 b'f4bd5e2fb678e83d' -KEYROM 24 D SLICE_X36Y62 b'd5468873f638a588' -KEYROM 25 A SLICE_X37Y62 b'b5ad3ef903bad1cc' -KEYROM 25 B SLICE_X37Y62 b'663b3762ed46a492' -KEYROM 25 C SLICE_X37Y62 b'3497837574de0f88' -KEYROM 25 D SLICE_X37Y62 b'1b439dd6d2953050' -KEYROM 26 A SLICE_X36Y63 b'dfcf77e3ddd6f0e9' -KEYROM 26 B SLICE_X36Y63 b'65f65be0de66224c' -KEYROM 26 C SLICE_X36Y63 b'5f963346abad671f' -KEYROM 26 D SLICE_X36Y63 b'553a2190a077d8fe' -KEYROM 27 A SLICE_X37Y63 b'6896a52d79ae7756' -KEYROM 27 B SLICE_X37Y63 b'259f1af5561c4ad4' -KEYROM 27 C SLICE_X37Y63 b'b3b4e703f9646c7f' -KEYROM 27 D SLICE_X37Y63 b'98dd0e7ae9851780' -KEYROM 28 A SLICE_X36Y64 b'dfd221616796d52a' -KEYROM 28 B SLICE_X36Y64 b'b9ccdb0ecd690519' -KEYROM 28 C SLICE_X36Y64 b'5872bdfb88eb525f' -KEYROM 28 D SLICE_X36Y64 b'0437219e51a726d4' -KEYROM 29 A SLICE_X37Y64 b'f3e99b98389bcac5' -KEYROM 29 B SLICE_X37Y64 b'1260bef6029bccec' -KEYROM 29 C SLICE_X37Y64 b'27e4152f337e8ec5' -KEYROM 29 D SLICE_X37Y64 b'ebbe10071b75ee85' -KEYROM 30 A SLICE_X36Y65 b'63441d998c5d1965' -KEYROM 30 B SLICE_X36Y65 b'cd2f2ba5cbb7ae89' -KEYROM 30 C SLICE_X36Y65 b'e73e6cc74573dda4' -KEYROM 30 D SLICE_X36Y65 b'546e28c78be6e124' -KEYROM 31 A SLICE_X37Y65 b'b040e7c8a01188c6' -KEYROM 31 B SLICE_X37Y65 b'a5e9f60f45b63895' -KEYROM 31 C SLICE_X37Y65 b'1b93da5e2b5e961b' -KEYROM 31 D SLICE_X37Y65 b'2a7d5c33be6a4499' +KEYROM 0 A SLICE_X36Y50 b'421756f8f8d1662a' +KEYROM 0 B SLICE_X36Y50 b'ae5a85e715ac7e2a' +KEYROM 0 C SLICE_X36Y50 b'44873c07724f9f49' +KEYROM 0 D SLICE_X36Y50 b'9272792b03ca7867' +KEYROM 1 A SLICE_X37Y50 b'fab84cfca11ede2a' +KEYROM 1 B SLICE_X37Y50 b'16a2c9190405f48f' +KEYROM 1 C SLICE_X37Y50 b'ed4b80ac17e0df75' +KEYROM 1 D SLICE_X37Y50 b'85afe5a0b08685aa' +KEYROM 2 A SLICE_X36Y51 b'3efecbd1d8b19485' +KEYROM 2 B SLICE_X36Y51 b'9f86c65af81f866b' +KEYROM 2 C SLICE_X36Y51 b'473bceb73c644545' +KEYROM 2 D SLICE_X36Y51 b'794073ccc983704e' +KEYROM 3 A SLICE_X37Y51 b'b6e17581bba7e057' +KEYROM 3 B SLICE_X37Y51 b'69434b43c05c9670' +KEYROM 3 C SLICE_X37Y51 b'7e884031616748b6' +KEYROM 3 D SLICE_X37Y51 b'c1bb36e7ca470895' +KEYROM 4 A SLICE_X36Y52 b'd10bde8405c7f1ba' +KEYROM 4 B SLICE_X36Y52 b'19a5a4b22af4bc14' +KEYROM 4 C SLICE_X36Y52 b'8eaa65fd7091f530' +KEYROM 4 D SLICE_X36Y52 b'76fbfec480ae2cb0' +KEYROM 5 A SLICE_X37Y52 b'4833163cca5c0c38' +KEYROM 5 B SLICE_X37Y52 b'5d1709acab5cbe11' +KEYROM 5 C SLICE_X37Y52 b'db0837fd62041bc9' +KEYROM 5 D SLICE_X37Y52 b'1c79cfa9eb05d7ba' +KEYROM 6 A SLICE_X36Y53 b'9f30e5d879ea9cdf' +KEYROM 6 B SLICE_X36Y53 b'f00ffbe982790287' +KEYROM 6 C SLICE_X36Y53 b'9bd6ab012d359d1f' +KEYROM 6 D SLICE_X36Y53 b'102b6e972fcad9d5' +KEYROM 7 A SLICE_X37Y53 b'f9f78d6454abd8f2' +KEYROM 7 B SLICE_X37Y53 b'2a2d0dd7eb12d077' +KEYROM 7 C SLICE_X37Y53 b'671a806cfc4f66df' +KEYROM 7 D SLICE_X37Y53 b'3210cedf98e99d96' +KEYROM 8 A SLICE_X36Y54 b'5759d45fd67f253d' +KEYROM 8 B SLICE_X36Y54 b'137050899d65f964' +KEYROM 8 C SLICE_X36Y54 b'1bb313adcc947f25' +KEYROM 8 D SLICE_X36Y54 b'950092520f28b15e' +KEYROM 9 A SLICE_X37Y54 b'5f6bc0a4477052d2' +KEYROM 9 B SLICE_X37Y54 b'd4f9cf0c83888cee' +KEYROM 9 C SLICE_X37Y54 b'6e2e7f233da9221e' +KEYROM 9 D SLICE_X37Y54 b'aa44adcdbfaba157' +KEYROM 10 A SLICE_X36Y55 b'f0095a35fd704458' +KEYROM 10 B SLICE_X36Y55 b'36a9b239b7bd16f0' +KEYROM 10 C SLICE_X36Y55 b'617d2b9f28a2ff45' +KEYROM 10 D SLICE_X36Y55 b'b74b1f3278638848' +KEYROM 11 A SLICE_X37Y55 b'9a2585412671d178' +KEYROM 11 B SLICE_X37Y55 b'a3ca7eaddb067e88' +KEYROM 11 C SLICE_X37Y55 b'27ee7f92af36cfd3' +KEYROM 11 D SLICE_X37Y55 b'c34867e495d89c9a' +KEYROM 12 A SLICE_X36Y56 b'ef56264e4b1870b2' +KEYROM 12 B SLICE_X36Y56 b'1d5f6fb74641af23' +KEYROM 12 C SLICE_X36Y56 b'7afb5baa51afac6a' +KEYROM 12 D SLICE_X36Y56 b'20e888d9611efa9d' +KEYROM 13 A SLICE_X37Y56 b'8804107a66cec3d3' +KEYROM 13 B SLICE_X37Y56 b'b2c890dcb75f30fb' +KEYROM 13 C SLICE_X37Y56 b'78bb97028f20186a' +KEYROM 13 D SLICE_X37Y56 b'c2575616967cfb60' +KEYROM 14 A SLICE_X36Y57 b'cae48cd69aee3815' +KEYROM 14 B SLICE_X36Y57 b'7cf2beb4e00cf757' +KEYROM 14 C SLICE_X36Y57 b'8b4fadfa39f2637b' +KEYROM 14 D SLICE_X36Y57 b'f754529a1653dc3d' +KEYROM 15 A SLICE_X37Y57 b'88b1779f8cc5023f' +KEYROM 15 B SLICE_X37Y57 b'a544f137ab11afd2' +KEYROM 15 C SLICE_X37Y57 b'e05bd7b858cab122' +KEYROM 15 D SLICE_X37Y57 b'c90ca56c470b2b98' +KEYROM 16 A SLICE_X36Y58 b'b6540f773774bacd' +KEYROM 16 B SLICE_X36Y58 b'69d825c84ba32f4b' +KEYROM 16 C SLICE_X36Y58 b'1f233362c06b3ec3' +KEYROM 16 D SLICE_X36Y58 b'db7f3a15ff421ff3' +KEYROM 17 A SLICE_X37Y58 b'6b356911c8ad50f5' +KEYROM 17 B SLICE_X37Y58 b'511a2a7b6a6cfe94' +KEYROM 17 C SLICE_X37Y58 b'fc7d3fe12c7af435' +KEYROM 17 D SLICE_X37Y58 b'd74a5619ae255693' +KEYROM 18 A SLICE_X36Y59 b'438bcc2444d0d551' +KEYROM 18 B SLICE_X36Y59 b'f1338e4e11c3d0c0' +KEYROM 18 C SLICE_X36Y59 b'a3b6949c95311e60' +KEYROM 18 D SLICE_X36Y59 b'eef5d045b195215d' +KEYROM 19 A SLICE_X37Y59 b'e7f27e86a7e08cdb' +KEYROM 19 B SLICE_X37Y59 b'9f33f1bbd25276ed' +KEYROM 19 C SLICE_X37Y59 b'596b5725dfa59a8b' +KEYROM 19 D SLICE_X37Y59 b'343dc25ab9668752' +KEYROM 20 A SLICE_X36Y60 b'7b3e6ed235b3bdba' +KEYROM 20 B SLICE_X36Y60 b'ec6ba9799b3ee836' +KEYROM 20 C SLICE_X36Y60 b'608d83ecfee86575' +KEYROM 20 D SLICE_X36Y60 b'efaeadfa7bfa676b' +KEYROM 21 A SLICE_X37Y60 b'6e2975b76c7ba07f' +KEYROM 21 B SLICE_X37Y60 b'dd7889bfe682e70c' +KEYROM 21 C SLICE_X37Y60 b'f34d0442b29f5cca' +KEYROM 21 D SLICE_X37Y60 b'c166e4f724724715' +KEYROM 22 A SLICE_X36Y61 b'8730b664136b9f58' +KEYROM 22 B SLICE_X36Y61 b'c6df173722641382' +KEYROM 22 C SLICE_X36Y61 b'a66edc5a63e70126' +KEYROM 22 D SLICE_X36Y61 b'c25d24e02d5a7df4' +KEYROM 23 A SLICE_X37Y61 b'b702b026ffaefd2c' +KEYROM 23 B SLICE_X37Y61 b'7e16cf2b5aa4bf4c' +KEYROM 23 C SLICE_X37Y61 b'42873fce9cb7d0e0' +KEYROM 23 D SLICE_X37Y61 b'ee501981d2575ecf' +KEYROM 24 A SLICE_X36Y62 b'cc082770312ef8b7' +KEYROM 24 B SLICE_X36Y62 b'dfa3c3c3ca9a8d57' +KEYROM 24 C SLICE_X36Y62 b'1003afc35336369e' +KEYROM 24 D SLICE_X36Y62 b'e7cdb4a27d0c366b' +KEYROM 25 A SLICE_X37Y62 b'dd12e9756e688232' +KEYROM 25 B SLICE_X37Y62 b'6cffa42e26440096' +KEYROM 25 C SLICE_X37Y62 b'b7f2b88659f094c7' +KEYROM 25 D SLICE_X37Y62 b'5d4f70178c300f5e' +KEYROM 26 A SLICE_X36Y63 b'a8a7d042e513e5f4' +KEYROM 26 B SLICE_X36Y63 b'c240e4b072a6be4f' +KEYROM 26 C SLICE_X36Y63 b'e3bf25ad10becda5' +KEYROM 26 D SLICE_X36Y63 b'f61f6dc0851bda27' +KEYROM 27 A SLICE_X37Y63 b'969b4d34ead9ea58' +KEYROM 27 B SLICE_X37Y63 b'280e664a27e263b2' +KEYROM 27 C SLICE_X37Y63 b'aca8e0322312bc89' +KEYROM 27 D SLICE_X37Y63 b'a21a42f70c2ab3cb' +KEYROM 28 A SLICE_X36Y64 b'2ce5344c87dedec7' +KEYROM 28 B SLICE_X36Y64 b'1d1c29bd777d9b82' +KEYROM 28 C SLICE_X36Y64 b'3f72f33c68929d4a' +KEYROM 28 D SLICE_X36Y64 b'39ee20ba584ebd0f' +KEYROM 29 A SLICE_X37Y64 b'7c508fae99f1f7fe' +KEYROM 29 B SLICE_X37Y64 b'9d4b1622f2003eec' +KEYROM 29 C SLICE_X37Y64 b'f2e37f0d9d235637' +KEYROM 29 D SLICE_X37Y64 b'0dbc1feb3f2627a8' +KEYROM 30 A SLICE_X36Y65 b'46f1504245f7f51d' +KEYROM 30 B SLICE_X36Y65 b'6a1d21ec413a09bb' +KEYROM 30 C SLICE_X36Y65 b'a2bdb8dc9552d79c' +KEYROM 30 D SLICE_X36Y65 b'747ae4b905ca4e75' +KEYROM 31 A SLICE_X37Y65 b'47bb20742224f4d1' +KEYROM 31 B SLICE_X37Y65 b'd3eea2385c090406' +KEYROM 31 C SLICE_X37Y65 b'2c9697f421e2c138' +KEYROM 31 D SLICE_X37Y65 b'9bee0802fd5b39cd' diff --git a/precursors/soc.svd b/precursors/soc.svd index 09324e4d4..ce3a991d8 100644 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1238,10 +1238,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0xb6dd1f78 + 0x5ac27d00 32 @@ -1258,7 +1258,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x00 + 0x08 32 @@ -3585,7 +3585,7 @@ inject too fast.]]> SEED1 0x0000 - 0x360403b2 + 0x22e343a6 32 @@ -3600,7 +3600,7 @@ inject too fast.]]> SEED0 0x0004 - 0x3ba4def5 + 0x19bfcf31 32 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index 15d744b17..a96841c59 100644 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/com/src/api.rs b/services/com/src/api.rs index ccc286f17..09c02879c 100644 --- a/services/com/src/api.rs +++ b/services/com/src/api.rs @@ -270,6 +270,12 @@ pub(crate) enum Opcode { /// wlan: debug infos WlanDebug, + /// wlan: get RSSI + WlanRssi, + + /// wlan: sync state (for resume) + WlanSyncState, + /// sets the EC-side com interrupt mask IntSetMask, @@ -296,10 +302,13 @@ pub(crate) enum Callback { pub enum ComIntSources { WlanRxReady, WlanIpConfigUpdate, - WlanSsidScanDone, + WlanSsidScanUpdate, + WlanSsidScanFinished, BatteryCritical, WlanTxErr, WlanRxErr, + Disconnect, + Connect, Invalid, } impl From for ComIntSources { @@ -307,10 +316,13 @@ impl From for ComIntSources { match n { com_rs_ref::INT_WLAN_RX_READY => ComIntSources::WlanRxReady, com_rs_ref::INT_WLAN_IPCONF_UPDATE => ComIntSources::WlanIpConfigUpdate, - com_rs_ref::INT_WLAN_SSID_UPDATE => ComIntSources::WlanSsidScanDone, + com_rs_ref::INT_WLAN_SSID_UPDATE => ComIntSources::WlanSsidScanUpdate, + com_rs_ref::INT_WLAN_SSID_FINISHED => ComIntSources::WlanSsidScanFinished, com_rs_ref::INT_BATTERY_CRITICAL => ComIntSources::BatteryCritical, com_rs_ref::INT_WLAN_TX_ERROR => ComIntSources::WlanTxErr, com_rs_ref::INT_WLAN_RX_ERROR => ComIntSources::WlanRxErr, + com_rs_ref::INT_WLAN_DISCONNECT => ComIntSources::Disconnect, + com_rs_ref::INT_WLAN_CONNECT_EVENT => ComIntSources::Connect, _ => ComIntSources::Invalid, } } @@ -320,10 +332,13 @@ impl From for u16 { match cis { ComIntSources::BatteryCritical => com_rs_ref::INT_BATTERY_CRITICAL, ComIntSources::WlanIpConfigUpdate => com_rs_ref::INT_WLAN_IPCONF_UPDATE, - ComIntSources::WlanSsidScanDone => com_rs_ref::INT_WLAN_SSID_UPDATE, + ComIntSources::WlanSsidScanUpdate => com_rs_ref::INT_WLAN_SSID_UPDATE, + ComIntSources::WlanSsidScanFinished => com_rs_ref::INT_WLAN_SSID_FINISHED, ComIntSources::WlanRxReady => com_rs_ref::INT_WLAN_RX_READY, ComIntSources::WlanTxErr => com_rs_ref::INT_WLAN_TX_ERROR, ComIntSources::WlanRxErr => com_rs_ref::INT_WLAN_RX_ERROR, + ComIntSources::Connect => com_rs_ref::INT_WLAN_CONNECT_EVENT, + ComIntSources::Disconnect => com_rs_ref::INT_WLAN_DISCONNECT, ComIntSources::Invalid => 0, } } diff --git a/services/com/src/lib.rs b/services/com/src/lib.rs index 193d65e3d..91106efca 100644 --- a/services/com/src/lib.rs +++ b/services/com/src/lib.rs @@ -6,6 +6,7 @@ pub mod api; pub use api::*; use api::{Callback, ComIntSources, NET_MTU, Opcode}; +use com_rs_ref::{DhcpState, LinkState}; use xous::{send_message, Error, CID, Message, msg_scalar_unpack}; use xous_ipc::{String, Buffer}; use num_traits::{ToPrimitive, FromPrimitive}; @@ -237,6 +238,8 @@ impl Com { send_message(self.conn, Message::new_scalar(Opcode::ScanOff.to_usize().unwrap(), 0, 0, 0, 0,)).map(|_| ()) } } + // this function no longer works, must rely on the event-based response via ComInt mechanism + #[deprecated] pub fn ssid_scan_updated(&self) -> Result { if let xous::Result::Scalar1(avail) = send_message(self.conn, Message::new_blocking_scalar(Opcode::SsidCheckUpdate.to_usize().unwrap(), 0, 0, 0, 0)).unwrap() { @@ -436,7 +439,6 @@ impl Com { } pub fn wlan_join(&mut self) -> Result { - // TODO: how to make this return success/fail status from WF200? send_message( self.conn, Message::new_scalar(Opcode::WlanJoin.to_usize().unwrap(), 0, 0, 0, 0), @@ -509,6 +511,34 @@ impl Com { buf.send(self.conn, Opcode::WlanSendPacket.to_u32().expect("WlanSendPacket failed")).or(Err(xous::Error::InternalError))?; Ok(()) } + /// signal strength in -dBm (pre-negated, for "proper" reporting, add a - sign) + pub fn wlan_get_rssi(&self) -> Result { + let response = send_message( + self.conn, + Message::new_blocking_scalar(Opcode::WlanRssi.to_usize().unwrap(), 0, 0, 0, 0) + ).expect("couldn't send WlanRssi message"); + if let xous::Result::Scalar1(rssi_usize) = response { + if rssi_usize & 0xFF_00 != 0 { + log::error!("got an error code in fetching the RSSI data: 0x{:x}", rssi_usize); + Err(xous::Error::UnknownError) + } else { + Ok((rssi_usize & 0xFF) as u8) + } + } else { + Err(xous::Error::InternalError) + } + } + pub fn wlan_sync_state(&self) -> Result<(LinkState, DhcpState), xous::Error> { + let response = send_message( + self.conn, + Message::new_blocking_scalar(Opcode::WlanSyncState.to_usize().unwrap(), 0, 0, 0, 0) + ).expect("couldn't send WlanRssi message"); + if let xous::Result::Scalar2(link, dhcp) = response { + Ok((LinkState::decode_u16(link as u16), DhcpState::decode_u16(dhcp as u16))) + } else { + Err(xous::Error::InternalError) + } + } pub fn ints_enable(&self, int_list: &[ComIntSources]) { let mut mask_val: u16 = 0; @@ -549,7 +579,7 @@ impl Com { Message::new_blocking_scalar(Opcode::IntAck.to_usize().unwrap(), ack_val as usize, 0, 0, 0) ).expect("couldn't send IntSetMask message"); } - pub fn ints_get_active(&self, int_list: &mut Vec::) -> Option { + pub fn ints_get_active(&self, int_list: &mut Vec::) -> (Option, usize, usize) { let response = send_message(self.conn, Message::new_blocking_scalar(Opcode::IntFetchVector.to_usize().unwrap(), 0, 0, 0, 0)) .expect("couldn't get IntFetchVector"); @@ -565,16 +595,18 @@ impl Com { rxlen = None; } else { if int_src == ComIntSources::WlanRxReady { - rxlen = Some(maybe_rxlen as u16) + rxlen = Some(maybe_rxlen as u16); + } else if int_src == ComIntSources::Connect { + rxlen = Some(maybe_rxlen as u16); } } } mask_bit <<= 1; } + (rxlen, ints, maybe_rxlen) } else { panic!("failed to send IntGetmask message"); } - rxlen } } diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 9b4882d48..c607f7d8c 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -766,6 +766,18 @@ fn xmain() -> ! { info!("TODO: implement WlanOff"); com.txrx(ComState::WLAN_OFF.verb); } + Some(Opcode::WlanRssi) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + com.txrx(ComState::WLAN_GET_RSSI.verb); + let maybe_rssi = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + // raw code sent, error interpretation done by lib function + xous::return_scalar(msg.sender, maybe_rssi as usize).unwrap(); + }), + Some(Opcode::WlanSyncState) => msg_blocking_scalar_unpack!(msg, _, _, _, _, { + com.txrx(ComState::WLAN_SYNC_STATE.verb); + let link = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + let dhcp = com.wait_txrx(ComState::LINK_READ.verb, Some(STD_TIMEOUT)); + xous::return_scalar2(msg.sender, link as usize, dhcp as usize).unwrap(); + }), Some(Opcode::WlanSetSSID) => { const WF200_SSID_LEN: usize = 32; let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; diff --git a/services/keyboard/src/main.rs b/services/keyboard/src/main.rs index c89aad2c1..3503a3a24 100644 --- a/services/keyboard/src/main.rs +++ b/services/keyboard/src/main.rs @@ -943,7 +943,7 @@ fn xmain() -> ! { }; log::trace!("got inject key, listener_conn: {:?}", listener_conn); if let Some(conn) = listener_conn { - info!("injecting key '{}'({:x})", key, key as u32); // always be noisy about this, it's an exploit path + log::info!("injecting key '{}'({:x})", key, key as u32); // always be noisy about this, it's an exploit path xous::send_message(conn, xous::Message::new_scalar(listener_op.unwrap(), key as u32 as usize, diff --git a/services/net/Cargo.toml b/services/net/Cargo.toml index 8c7766921..025ad483e 100644 --- a/services/net/Cargo.toml +++ b/services/net/Cargo.toml @@ -23,6 +23,8 @@ com = {path = "../com"} byteorder = { version = "1.0", default-features = false } trng = {path = "../trng"} com_rs-ref = {path = "../../imports/com_rs-ref"} +modals = {path = "../modals"} +locales = {path = "../../locales"} # for automatic SSID management and AP list storage pddb = {path = "../pddb"} diff --git a/services/net/locales/i18n.json b/services/net/locales/i18n.json new file mode 100644 index 000000000..dafd0fba3 --- /dev/null +++ b/services/net/locales/i18n.json @@ -0,0 +1,12 @@ +{ + "net.ec_rev_old": { + "en": "EC firmware is out of date. Wifi connection manager cannot start.", + "zh": "EC 固件已过期,无法启动连接管理器.", + "en-audio": "EC firmware is out of date. Wifi connection manager cannot start." + }, + "net.ec_current_rev": { + "en": "Current EC rev: ", + "zh": "当前的 EC 修订版: ", + "en-audio": "Current EC rev: " + } +} \ No newline at end of file diff --git a/services/net/src/api.rs b/services/net/src/api.rs index 59b8f5e91..df2e674ae 100644 --- a/services/net/src/api.rs +++ b/services/net/src/api.rs @@ -21,7 +21,7 @@ pub const AP_DICT_NAME: &'static str = "wlan_ap_list"; #[allow(dead_code)] /// minimum revision required for compatibility with Net crate -pub const MIN_EC_REV: u32 = 0x00_09_05_07; +pub const MIN_EC_REV: u32 = 0x00_09_05_0F; /// Dispatch opcodes to the Net crate main loop. #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] diff --git a/services/net/src/connection_manager.rs b/services/net/src/connection_manager.rs index e5e0ac182..90280e11f 100644 --- a/services/net/src/connection_manager.rs +++ b/services/net/src/connection_manager.rs @@ -2,18 +2,22 @@ use crate::api::*; use std::sync::Arc; use core::sync::atomic::{AtomicU32, Ordering}; use com::{WlanStatus, WlanStatusIpc}; +use com_rs_ref::{ConnectResult, LinkState}; use net::MIN_EC_REV; use xous::{msg_blocking_scalar_unpack, msg_scalar_unpack, send_message, Message}; use xous_ipc::Buffer; use num_traits::*; use std::io::Read; -use std::collections::HashMap; +use std::collections::{HashMap, HashSet}; +use locales::t; +use crate::ComIntSources; #[allow(dead_code)] -const BOOT_POLL_INTERVAL_MS: usize = 5_758; // a slightly faster poll during boot so we acquire wifi faster once PDDB is mounted +const BOOT_POLL_INTERVAL_MS: usize = 3_758; // a slightly faster poll during boot so we acquire wifi faster once PDDB is mounted /// this is shared externally so other functions (e.g. in status bar) that want to query the net manager know how long to back off, otherwise the status query will block #[allow(dead_code)] -const POLL_INTERVAL_MS: usize = 20_151; // stagger slightly off of an integer-seconds interval to even out loads +const POLL_INTERVAL_MS: usize = 10_151; // stagger slightly off of an integer-seconds interval to even out loads. impacts rssi update frequency. +const INTERVALS_BEFORE_RETRY: usize = 3; // how many poll intervals we'll wait before we give up and try a new AP #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)] pub(crate) enum ConnectionManagerOpcode { @@ -22,9 +26,29 @@ pub(crate) enum ConnectionManagerOpcode { Stop, SubscribeWifiStats, UnsubWifiStats, + ComInt, + SuspendResume, Quit, } +#[derive(Eq, PartialEq, Copy, Clone, Debug)] +enum WifiState { + Unknown, + Connecting, + WaitDhcp, + Retry, + InvalidAp, + InvalidAuth, + Connected, + Disconnected, + Error +} +#[derive(Eq, PartialEq)] +enum SsidScanState { + Idle, + Scanning, +} + pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc) { let tt = ticktimer_server::Ticktimer::new().unwrap(); let xns = xous_names::XousNames::new().unwrap(); @@ -34,6 +58,7 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc= MIN_EC_REV; if !rev_ok { log::warn!("EC firmware is too old to interoperate with the connection manager."); + let mut note = String::from(t!("net.ec_rev_old", xous::LANG)); + note.push_str(&format!("\n\n{}{}.{}.{}+{}", t!("net.ec_current_rev", xous::LANG), maj, min, rev, commits)); + modals.show_notification(¬e).unwrap(); } let mut run = rev_ok; @@ -49,93 +77,262 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc::new(); + let mut wifi_state = WifiState::Unknown; + let mut last_wifi_state = wifi_state; + let mut ssid_list = HashSet::::new(); // we're throwing away the RSSI for now and just going by name + let mut ssid_attempted = HashSet::::new(); + let mut wait_count = 0; + + let mut susres = susres::Susres::new( + Some(susres::SuspendOrder::Early), &xns, + ConnectionManagerOpcode::SuspendResume as u32, self_cid).expect("couldn't create suspend/resume object"); + + com.set_ssid_scanning(true).unwrap(); // kick off an initial SSID scan, we'll always want this info regardless + let mut scan_state = SsidScanState::Scanning; + send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), current_interval, 0, 0, 0)).expect("couldn't kick off next poll"); loop { let msg = xous::receive_message(sid).unwrap(); log::debug!("got msg: {:?}", msg); match FromPrimitive::from_usize(msg.body.id()) { + Some(ConnectionManagerOpcode::SuspendResume) => xous::msg_scalar_unpack!(msg, token, _, _, _, { + // for now, nothing to do to prepare for suspend... + susres.suspend_until_resume(token).expect("couldn't execute suspend/resume"); + // on resume, check with the EC and see where the link state ended up + let (res_linkstate, _res_dhcpstate) = com.wlan_sync_state().unwrap(); + match res_linkstate { + LinkState::Connected => { + match wifi_state { + WifiState::Connected => { + // everything is A-OK + }, + WifiState::Error => { + // let the error handler do its thing on the next pump cycle + } + _ => { + // somehow, we thought we were disconnected, but then we resumed and we're magically connected. + // it's not clear to me how we get into this state, so let's be conservative and just leave the link and restart things. + com.wlan_leave().expect("couldn't issue leave command"); // leave the previous config to reset state + netmgr.reset(); + wifi_state = WifiState::Disconnected; + if scan_state == SsidScanState::Idle { + com.set_ssid_scanning(true).unwrap(); + scan_state = SsidScanState::Scanning; + } + send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), current_interval, 0, 0, 0)).expect("couldn't kick off next poll"); + } + } + } + LinkState::WFXError => { + wifi_state = WifiState::Error; + } + _ => { // should approximately be a "disconnected" state. + match wifi_state { + WifiState::Connected => { + // move the wifi into the disconnected state to re-initiate a connection + netmgr.reset(); + // reset the stats cache, and update subscribers that we're disconnected + wifi_stats_cache = WlanStatus::from_ipc(WlanStatusIpc::default()); + for &sub in status_subscribers.keys() { + let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); + buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); + } + wifi_state = WifiState::Disconnected; + // kick off an SSID scan + if scan_state == SsidScanState::Idle { + com.set_ssid_scanning(true).unwrap(); + scan_state = SsidScanState::Scanning; + } + } + WifiState::Error => { + // let the error handler do its thing on the next pump cycle + } + _ => { + // we were in some intermediate state, just "snap" us to disconnected and let the state machine take care of the rest + wifi_state = WifiState::Disconnected; + } + } + } + } + }), Some(ConnectionManagerOpcode::Run) => msg_scalar_unpack!(msg, _, _, _, _, { if !run { run = true; send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), 0, 0, 0, 0)).expect("couldn't kick off next poll"); } }), + Some(ConnectionManagerOpcode::ComInt) => msg_scalar_unpack!(msg, ints, raw_arg, 0, 0, { + log::debug!("debug: {:x}, {:x}", ints, raw_arg); + let mut mask_bit: u16 = 1; + for _ in 0..16 { + match ComIntSources::from(mask_bit & (ints as u16)) { + ComIntSources::Connect => { + wifi_state = match ConnectResult::decode_u16(raw_arg as u16) { + ConnectResult::Success => { + com.set_ssid_scanning(false).unwrap(); + scan_state = SsidScanState::Idle; + activity_interval.store(0, Ordering::SeqCst); + WifiState::WaitDhcp + }, + ConnectResult::NoMatchingAp => WifiState::InvalidAp, + ConnectResult::Timeout => WifiState::Retry, + ConnectResult::Reject | ConnectResult::AuthFail => WifiState::InvalidAuth, + ConnectResult::Aborted => WifiState::Retry, + ConnectResult::Error => WifiState::Error, + ConnectResult::Pending => WifiState::Error, + }; + log::debug!("comint new wifi state: {:?}", wifi_state); + } + ComIntSources::Disconnect => { + ssid_list.clear(); // clear the ssid list because a likely cause of disconnect is we've moved out of range + com.set_ssid_scanning(true).unwrap(); + scan_state = SsidScanState::Scanning; + wifi_state = WifiState::Disconnected; + }, + ComIntSources::WlanSsidScanUpdate => { + // aggressively pre-fetch results so we can connect as soon as we see an SSID + match com.ssid_fetch_as_list() { + Ok(slist) => { + for (_rssi, ssid) in slist.iter() { + ssid_list.insert(ssid.to_string()); + } + }, + _ => continue, + } + log::debug!("ssid scan update"); + }, + ComIntSources::WlanSsidScanFinished => { + match com.ssid_fetch_as_list() { + Ok(slist) => { + for (_rssi, ssid) in slist.iter() { + ssid_list.insert(ssid.to_string()); + } + }, + _ => continue, + } + scan_state = SsidScanState::Idle; + } + ComIntSources::WlanIpConfigUpdate => { + activity_interval.store(0, Ordering::SeqCst); + wifi_state = WifiState::Connected; + log::debug!("comint new wifi state: {:?}", wifi_state); + // this is the "first" path -- it's hit immediately on connect. + // relay status updates to any subscribers that want to know if a state has changed + wifi_stats_cache = com.wlan_status().unwrap(); + log::debug!("stats update: {:?}", wifi_stats_cache); + for &sub in status_subscribers.keys() { + let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); + buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); + } + } + _ => {} + } + mask_bit <<= 1; + } + }), Some(ConnectionManagerOpcode::Poll) => msg_scalar_unpack!(msg, _, _, _, _, { if activity_interval.fetch_add(current_interval as u32, Ordering::SeqCst) > current_interval as u32 { log::info!("wlan activity interval timeout"); // if the pddb isn't mounted, don't even bother checking -- we can't connect until we have a place to get keys if pddb.is_mounted() && rev_ok { mounted = true; - // the status check code is going to get refactored, so this is a "bare minimum" check - let new_state = com.wlan_status().unwrap(); - if wifi_stats_cache.link_state != new_state.link_state || - wifi_stats_cache.ssid.unwrap_or(com::SsidRecord::default()).name != new_state.ssid.unwrap_or(com::SsidRecord::default()).name || - wifi_stats_cache.ssid.unwrap_or(com::SsidRecord::default()).rssi != new_state.ssid.unwrap_or(com::SsidRecord::default()).rssi - { + + if last_wifi_state == WifiState::Connected && wifi_state != WifiState::Connected { + log::debug!("sending disconnect update to subscribers"); + // reset the stats cache, and update subscribers that we're disconnected + wifi_stats_cache = WlanStatus::from_ipc(WlanStatusIpc::default()); for &sub in status_subscribers.keys() { let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); } } - wifi_stats_cache = new_state; - let config = netmgr.get_ipv4_config(); - if wifi_stats_cache.link_state == com_rs_ref::LinkState::WFXError { - com.wlan_leave().expect("couldn't issue leave command"); // this may not be received by the wf200, *but* it will also re-init the DHCP stack on the EC - netmgr.reset(); // this will clear our internal net state - // the wfx chip is wedged. kick it. This call has a built-in 2 second delay. - com.wifi_reset().expect("couldn't reset the wf200 chip"); - } - let needs_reconnect = - if wifi_stats_cache.link_state == com_rs_ref::LinkState::Connected { - if let Some(config) = config { // check that the EC's view of the world is synchronized with our view - // is it enough to just check that the address is the same? - if config.addr != wifi_stats_cache.ipv4.addr { - true - } else { - false - } - } else { - true - } - } else { - true - }; - if needs_reconnect { - log::info!("wlan is not connected, attempting auto-reconnect to known AP list"); - if let Ok(ap_list) = pddb.list_keys(AP_DICT_NAME, None) { - com.wlan_leave().expect("couldn't issue leave command"); // leave the previous config to reset state - netmgr.reset(); - // TODO: add an SSID scan phase, so we only try to connect to SSIDs that are currently visible. - // for now, just try every single one as a brute force approach. - for ap in ap_list { - let mut wpa_pw_file = pddb.get(AP_DICT_NAME, &ap, None, false, false, None, Some(||{})).expect("couldn't retrieve AP password"); - let mut wp_pw_raw = [0u8; com::api::WF200_PASS_MAX_LEN]; - if let Ok(readlen) = wpa_pw_file.read(&mut wp_pw_raw) { - let pw = std::str::from_utf8(&wp_pw_raw[..readlen]).expect("password was not valid utf-8"); - com.wlan_set_ssid(&ap).expect("couldn't set SSID"); - com.wlan_set_pass(pw).expect("couldn't set password"); - com.wlan_join().expect("couldn't issue join command"); - } - // this needs to not be a dead-wait loop, but for now the WLAN API doesn't support anything better - tt.sleep_ms(5_000).unwrap(); - wifi_stats_cache = com.wlan_status().unwrap(); - if wifi_stats_cache.link_state == com_rs_ref::LinkState::Connected { - break; - } - } - for &sub in status_subscribers.keys() { - let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); - buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); - } - } else { - log::warn!("Connection manager couldn't access {}, but continuing to poll.", AP_DICT_NAME); + + if let Ok(ap_list_vec) = pddb.list_keys(AP_DICT_NAME, None) { + let mut ap_list = HashSet::::new(); + for ap in ap_list_vec { + ap_list.insert(ap); + } + match wifi_state { + WifiState::Unknown | WifiState::Disconnected | WifiState::InvalidAp | WifiState::InvalidAuth => { + if scan_state == SsidScanState::Scanning { + com.set_ssid_scanning(false).unwrap(); + scan_state = SsidScanState::Idle; + } + if let Some(ssid) = get_next_ssid(&mut ssid_list, &mut ssid_attempted, ap_list) { + let mut wpa_pw_file = pddb.get(AP_DICT_NAME, &ssid, None, false, false, None, Some(||{})).expect("couldn't retrieve AP password"); + let mut wp_pw_raw = [0u8; com::api::WF200_PASS_MAX_LEN]; + if let Ok(readlen) = wpa_pw_file.read(&mut wp_pw_raw) { + let pw = std::str::from_utf8(&wp_pw_raw[..readlen]).expect("password was not valid utf-8"); + log::info!("Attempting wifi connection: {}", ssid); + com.wlan_set_ssid(&ssid).expect("couldn't set SSID"); + com.wlan_set_pass(pw).expect("couldn't set password"); + com.wlan_join().expect("couldn't issue join command"); + wifi_state = WifiState::Connecting; + } + } + } + WifiState::WaitDhcp | WifiState::Connecting => { + log::debug!("still waiting for connection result..."); + wait_count += 1; + if wait_count > INTERVALS_BEFORE_RETRY { + wait_count = 0; + wifi_state = WifiState::Retry; + } + } + WifiState::Retry => { + log::debug!("got Retry on connect"); + com.wlan_leave().expect("couldn't issue leave command"); // leave the previous config to reset state + netmgr.reset(); + wifi_state = WifiState::Disconnected; + if scan_state == SsidScanState::Idle { + com.set_ssid_scanning(true).unwrap(); + scan_state = SsidScanState::Scanning; + } + send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), current_interval, 0, 0, 0)).expect("couldn't kick off next poll"); + } + WifiState::Error => { + log::debug!("got error on connect, resetting wifi chip"); + com.wifi_reset().expect("couldn't reset the wf200 chip"); + netmgr.reset(); + wifi_state = WifiState::Disconnected; + if scan_state == SsidScanState::Idle { + com.set_ssid_scanning(true).unwrap(); + scan_state = SsidScanState::Scanning; + } + send_message(self_cid, Message::new_scalar(ConnectionManagerOpcode::Poll.to_usize().unwrap(), current_interval, 0, 0, 0)).expect("couldn't kick off next poll"); + } + WifiState::Connected => { + // this is the "rare" path -- it's if we connected and not much is going on, so we timeout and hit this ping + log::debug!("connected, updating stats cache"); + // relay status updates to any subscribers that want to know if a state has changed + wifi_stats_cache = com.wlan_status().unwrap(); + log::debug!("stats update: {:?}", wifi_stats_cache); + for &sub in status_subscribers.keys() { + let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); + buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); + } + } + } + } + } + last_wifi_state = wifi_state; + } + + if wifi_state == WifiState::Connected { + if let Some(ssid_stats) = wifi_stats_cache.ssid.as_mut() { + let rssi_u8 = com.wlan_get_rssi().ok().unwrap_or(255); + // only send an update if the RSSI changed + if ssid_stats.rssi != rssi_u8 { + ssid_stats.rssi = rssi_u8; + log::debug!("stats update: {:?}", wifi_stats_cache); + for &sub in status_subscribers.keys() { + let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap(); + buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap(); } - } else { - // we're up, reset the interval - activity_interval.store(0, Ordering::SeqCst); } } } + if run { tt.sleep_ms(current_interval).unwrap(); if !mounted { @@ -187,4 +384,50 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc, ssid_attempted: &mut HashSet, ap_list: HashSet::) -> Option { + log::trace!("ap_list: {:?}", ap_list); + log::trace!("ssid_list: {:?}", ssid_list); + // 1. find the intersection of ap_list and ssid_list to create a candidate_list + let all_candidate_list_ref = ap_list.intersection(ssid_list).collect::>(); + // this copy is required to perform the next set computation + let mut all_candidate_list = HashSet::::new(); + for c in all_candidate_list_ref { + all_candidate_list.insert(String::from(c)); + } + log::trace!("intersection: {:?}", all_candidate_list); + + log::trace!("ssids already attempted: {:?}", ssid_attempted); + // 2. find the complement of ssid_attempted and candidate_list + let untried_candidate_list_ref = all_candidate_list.difference(ssid_attempted).collect::>(); + // this copy breaks the mutability issue with changing ssid_attempted after the difference is computed + let mut untried_candidate_list = HashSet::::new(); + for c in untried_candidate_list_ref { + untried_candidate_list.insert(String::from(c)); + } + log::trace!("untried_candidates: {:?}", untried_candidate_list); + + if untried_candidate_list.len() > 0 { + if let Some(candidate) = untried_candidate_list.into_iter().next() { + ssid_attempted.insert(candidate.to_string()); + log::debug!("SSID connect attempt: {:?}", candidate); + Some(candidate.to_string()) + } else { + log::error!("We should have had at least one item in the candidate list, but found none."); + None + } + } else { + // clear the ssid_attempted list and start from scratch + log::debug!("Exhausted all candidates, starting over again..."); + ssid_attempted.clear(); + if let Some(candidate) = all_candidate_list.iter().next() { + ssid_attempted.insert(candidate.to_string()); + log::debug!("SSID connect attempt: {:?}", candidate); + Some(candidate.to_string()) + } else { + log::info!("No SSID candidates visible"); + None + } + } } \ No newline at end of file diff --git a/services/net/src/main.rs b/services/net/src/main.rs index 5b1dfc0ed..06b925cc0 100644 --- a/services/net/src/main.rs +++ b/services/net/src/main.rs @@ -107,6 +107,10 @@ fn xmain() -> ! { com_int_list.push(ComIntSources::WlanIpConfigUpdate); com_int_list.push(ComIntSources::WlanRxReady); com_int_list.push(ComIntSources::BatteryCritical); + com_int_list.push(ComIntSources::Connect); + com_int_list.push(ComIntSources::Disconnect); + com_int_list.push(ComIntSources::WlanSsidScanUpdate); + com_int_list.push(ComIntSources::WlanSsidScanFinished); com.ints_enable(&com_int_list); com_int_list.clear(); com.ints_get_active(&mut com_int_list); @@ -549,8 +553,23 @@ fn xmain() -> ! { Some(Opcode::ComInterrupt) => { com_int_list.clear(); - let maybe_rxlen = com.ints_get_active(&mut com_int_list); + let (maybe_rxlen, ints, raw_rxlen) = com.ints_get_active(&mut com_int_list); log::debug!("COM got interrupts: {:?}, {:?}", com_int_list, maybe_rxlen); + // forward the interrupt to the connection manager as well + match xous::try_send_message(cm_cid, Message::new_scalar( + connection_manager::ConnectionManagerOpcode::ComInt.to_usize().unwrap(), + ints, + raw_rxlen, + 0, 0 + )) { + Ok(_) => {}, + Err(xous::Error::ServerQueueFull) => { + log::warn!("Our net queue runneth over, interrupts were dropped."); + }, + Err(e) => { + log::error!("Unhandled error forwarding ComInt to the connection manager: {:?}", e); + } + }; for &pending in com_int_list.iter() { if pending == ComIntSources::Invalid { log::error!("COM interrupt vector had an error, ignoring event."); @@ -650,11 +669,8 @@ fn xmain() -> ! { } } }, - ComIntSources::WlanSsidScanDone => { - log::info!("got ssid scan done"); - }, _ => { - log::error!("Invalid interrupt type received"); + log::debug!("Unhandled: {:?}", pending); } } } diff --git a/services/shellchat/src/cmds/ssid.rs b/services/shellchat/src/cmds/ssid.rs index 924bb75d4..77eec8e62 100644 --- a/services/shellchat/src/cmds/ssid.rs +++ b/services/shellchat/src/cmds/ssid.rs @@ -63,7 +63,7 @@ impl<'a> ShellCmdApi<'a> for Ssid { } if !responded { xous::send_message(callback_conn, Message::Scalar(ScalarMessage{ - id: cb_id as usize, arg1: ScanResult::Timeout.to_usize().unwrap(), arg2: 0, arg3: 0, arg4: 0, + id: cb_id as usize, arg1: ScanResult::Ok.to_usize().unwrap(), arg2: 0, arg3: 0, arg4: 0, })).unwrap(); } }