1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: demo_AcTestMain.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev:$
14 *---------------------------------------------------------------------------*/
15
16 #include <nn.h>
17 #include <cstring>
18
19 #define SSID "your_SSID"
20
21 static size_t STACK_SIZE = 4096;
22 static nn::os::Event s_DisconnectEvent(false);
23
DisconnectWaitThread()24 extern "C" void DisconnectWaitThread()
25 {
26 NN_LOG( "Start to wait for a disconnect event.\n" );
27 s_DisconnectEvent.Wait();
28 NN_LOG( "Signal disconnect event!\n" );
29 }
30
nnMain(void)31 extern "C" void nnMain( void )
32 {
33 // Call only nn::applet::Enable to also allow execution from the HOME Menu
34 // HOME Menu transitions, POWER Button presses, and sleep are all unsupported
35 nn::applet::Enable();
36
37 nn::Result result;
38
39 nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromMicroSeconds(2000));
40
41 NN_LOG("client: Initialize AC\n");
42 nn::fs::Initialize();
43 result = nn::ac::Initialize();
44 if( result.IsSuccess() )
45 {
46 NN_LOG("client: Save network setting A.\n");
47 u8 key[64];
48 key[0] = '1';
49 key[1] = '2';
50 key[2] = '3';
51 key[3] = '4';
52 key[4] = '5';
53 result = nn::ac::DebugSetNetworkSetting1( reinterpret_cast<const u8*>(SSID), std::strlen(SSID), nn::ac::WEP_40BIT, key, 40/8 );
54 if( result.IsSuccess() )
55 {
56 // Saved successfully
57 nn::ac::Config config;
58 nn::ac::CreateDefaultConfig( &config );
59
60 nn::ac::RegisterDisconnectEvent( &s_DisconnectEvent );
61 nn::os::Thread thread;
62 thread.StartUsingAutoStack( DisconnectWaitThread, STACK_SIZE );
63 thread.Detach();
64
65 NN_LOG("client: Connecting\n");
66 result = nn::ac::Connect( config );
67 if( result.IsSuccess() )
68 {
69 // Connection successful
70 NN_LOG("Successfully connected.\n");
71
72 NN_LOG("client: Close\n");
73 nn::ac::Close();
74 }
75 else
76 {
77 // Connection failure
78 NN_LOG("Connection failed.\n");
79 }
80 }
81 else
82 {
83 // Failed to save
84 NN_LOG("Save failed.\n");
85 }
86 }
87 else
88 {
89 NN_LOG("client: Initialization failure\n");
90 }
91
92 NN_LOG("client: Finalize AC\n");
93 nn::ac::Finalize();
94
95 NN_LOG("Exit client\n");
96 while(true)
97 {
98 nn::os::Thread::Sleep(nn::fnd::TimeSpan::FromSeconds(1));
99 }
100 }
101