1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - OS
3 File: ownerInfoEx.c
4
5 Copyright 2003-2008 Nintendo. 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 $Date:: 2008-11-13#$
14 $Rev: 9302 $
15 $Author: hirose_kazuki $
16 *---------------------------------------------------------------------------*/
17
18 #include <nitro/os/common/ownerInfo.h>
19 #include <nitro/os/common/systemWork.h>
20 #include <nitro/os/common/emulator.h>
21 #include <twl/os/common/ownerInfoEx.h>
22 #include <twl/os/common/ownerInfoEx_private.h>
23 #include <twl/hw/common/mmap_parameter.h>
24
25 #ifdef SDK_ARM9
26 #include <twl/hw/ARM9/mmap_main.h>
27 #else //SDK_ARM7
28 #include <twl/hw/ARM7/mmap_main.h>
29 #endif
30
31 /*---------------------------------------------------------------------------*
32 Constants
33 *---------------------------------------------------------------------------*/
34
35 //
36 // Each value of the owner information is read to a fixed address of the main memory by the launcher
37 #define OS_ADDR_TWL_SETTINGSDATA ( (OSTWLSettingsData *)HW_PARAM_TWL_SETTINGS_DATA )
38 #define OS_ADDR_TWL_HWNORMALINFO ( (OSTWLHWNormalInfo *)HW_PARAM_TWL_HW_NORMAL_INFO )
39
40
41 /*---------------------------------------------------------------------------*
42 function definitions
43 *---------------------------------------------------------------------------*/
44
45 /*---------------------------------------------------------------------------*
46 Name: OS_GetOwnerInfoEx
47
48 Description: Gets the owner information. TWL version
49 Information that also exists in NITRO is gotten from the same location as the NITRO version.
50 The language code (language) can be different between TWL and NITRO, so get information from TWL.
51
52
53 Arguments: info: Pointer to the buffer getting the owner information.
54 Data gets written to this buffer.
55 (*) TWL information can only be gotten in TWL mode
56 (When not running in TWL, this is always 0)
57
58 Returns: None.
59 *---------------------------------------------------------------------------*/
OS_GetOwnerInfoEx(OSOwnerInfoEx * info)60 void OS_GetOwnerInfoEx(OSOwnerInfoEx *info)
61 {
62 NVRAMConfig *src;
63 OSTWLSettingsData *twlSettings;
64
65 // Get the same information as as NITRO from the NITRO region (copy-paste sometimes)
66 src = (NVRAMConfig *)(OS_GetSystemWork()->nvramUserInfo);
67 //info->language = (u8)(src->ncd.option.language); //The language code is designated for TWL mode and for NITRO mode
68 info->favoriteColor = (u8)(src->ncd.owner.favoriteColor);
69 info->birthday.month = (u8)(src->ncd.owner.birthday.month);
70 info->birthday.day = (u8)(src->ncd.owner.birthday.day);
71 info->nickNameLength = (u16)(src->ncd.owner.nickname.length);
72 info->commentLength = (u16)(src->ncd.owner.comment.length);
73 MI_CpuCopy16(src->ncd.owner.nickname.str,
74 info->nickName, OS_OWNERINFO_NICKNAME_MAX * sizeof(u16));
75 MI_CpuCopy16(src->ncd.owner.comment.str, info->comment, OS_OWNERINFO_COMMENT_MAX * sizeof(u16));
76 info->nickName[OS_OWNERINFO_NICKNAME_MAX] = 0;
77 info->comment[OS_OWNERINFO_COMMENT_MAX] = 0;
78
79 // Get the TWL information
80 if( OS_IsRunOnTwl() )
81 {
82 twlSettings = (OSTWLSettingsData*) OS_ADDR_TWL_SETTINGSDATA ;
83 info->country = twlSettings->country;
84 info->language = twlSettings->language;
85 }
86 else
87 {
88 info->country = 0;
89 info->language = (u8)(src->ncd.option.language);
90 }
91 }
92
93 /*---------------------------------------------------------------------------*
94 Name: OS_IsAvailableWireless
95
96 Description: Get information on the validity/invalidity of wireless module RF unit
97
98 Arguments: None.
99
100 Returns: TRUE if valid; FALSE if invalid
101 When not running in TWL, this is always TRUE
102 *---------------------------------------------------------------------------*/
103 #ifdef SDK_TWL
104 #include <twl/ltdmain_begin.h>
105 static BOOL OS_IsAvailableWireless_ltdmain(void);
OS_IsAvailableWireless_ltdmain(void)106 static BOOL OS_IsAvailableWireless_ltdmain(void)
107 {
108 OSTWLSettingsData *p;
109 p = (OSTWLSettingsData*)OS_ADDR_TWL_SETTINGSDATA;
110 return (p->flags.isAvailableWireless == 0x1);
111 }
112 #include <twl/ltdmain_end.h>
113 #endif
114
115 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
OS_IsAvailableWireless(void)116 BOOL OS_IsAvailableWireless(void)
117 {
118 BOOL result;
119 if( OS_IsRunOnTwl() )
120 {
121 #ifdef SDK_TWL
122 result = OS_IsAvailableWireless_ltdmain();
123 #endif
124 }
125 else
126 {
127 result = TRUE;
128 }
129 return (result);
130 }
131
132 /*---------------------------------------------------------------------------*
133 Name: OS_IsAgreeEULA
134
135 Description: Gets whether EULA was agreed to.
136
137 Arguments: None.
138
139 Returns: BOOL: TRUE if EULA agreed to; FALSE if no agreement.
140 When not running in TWL, this is always FALSE.
141 *---------------------------------------------------------------------------*/
OS_IsAgreeEULA(void)142 BOOL OS_IsAgreeEULA(void)
143 {
144 OSTWLSettingsData *p;
145 if( OS_IsRunOnTwl() )
146 {
147 p = (OSTWLSettingsData*)OS_ADDR_TWL_SETTINGSDATA;
148 return (p->flags.isAgreeEULAFlagList & 0x01) ? TRUE : FALSE;
149 }
150 else
151 {
152 return FALSE;
153 }
154 }
155
156 /*---------------------------------------------------------------------------*
157 Name: OS_GetAgreeEULAVersion
158
159 Description: Gets the agreed-to EULA version.
160
161 Arguments: None.
162
163 Returns: agreedEulaVersion: Agreed EULA version (0-255 characters).
164 *---------------------------------------------------------------------------*/
OS_GetAgreedEULAVersion(void)165 u8 OS_GetAgreedEULAVersion( void )
166 {
167 OSTWLSettingsData *p;
168 if( OS_IsRunOnTwl() )
169 {
170 p = (OSTWLSettingsData*)OS_ADDR_TWL_SETTINGSDATA;
171 return p->agreeEulaVersion[ 0 ];
172 }
173 else
174 {
175 return 0;
176 }
177 }
178
179
180 /*---------------------------------------------------------------------------*
181 Name: OS_GetROMHeaderEULAVersion
182
183 Description: Gets version of EULA registered in ROM header of application.
184
185 Arguments: None.
186
187 Returns: cardEulaVersion: EULA version registered in ROM header of application (0-255 characters).
188 *---------------------------------------------------------------------------*/
OS_GetROMHeaderEULAVersion(void)189 u8 OS_GetROMHeaderEULAVersion( void )
190 {
191 if( OS_IsRunOnTwl() )
192 {
193 // Hard coding for the agree_EULA version in the ROM header.
194 return *(u8 *)( HW_TWL_ROM_HEADER_BUF + 0x020e );
195 }
196 else
197 {
198 return 0;
199 }
200 }
201
202
203 /*---------------------------------------------------------------------------*
204 Name: OS_GetParentalControlInfoPtr
205
206 Description: Gets the pointer to parental controls information
207
208 Arguments: None.
209
210 Returns: Return the pointer.
211 Return NULL when not running in TWL.
212 *---------------------------------------------------------------------------*/
OS_GetParentalControlInfoPtr(void)213 const OSTWLParentalControl* OS_GetParentalControlInfoPtr(void)
214 {
215 OSTWLSettingsData *p;
216 if( OS_IsRunOnTwl() )
217 {
218 p = (OSTWLSettingsData*)OS_ADDR_TWL_SETTINGSDATA;
219 return &(p->parentalControl);
220 }
221 else
222 {
223 return NULL;
224 }
225 }
226
227 /*---------------------------------------------------------------------------*
228 Name: OS_IsParentalControledApp
229
230 Description: Determines whether parental controls should be applied when starting the application.
231
232
233 Arguments: appRatingInfo: Offset within ROM header of application
234 Specify pointer to 16-byte rating information embedded in the 0x2f0 position
235
236
237 Returns: Return TRUE to apply parental controls and prompt password input. For applications that can be started without restriction, return FALSE.
238
239
240 *---------------------------------------------------------------------------*/
241 /* The following code is located in the TWL extended memory region */
242 #ifdef SDK_TWL
243 #include <twl/ltdmain_begin.h>
244 #endif
245 BOOL OSi_IsParentalControledAppCore(u8* appRatingInfo);
246
247 BOOL
OSi_IsParentalControledAppCore(u8 * appRatingInfo)248 OSi_IsParentalControledAppCore(u8* appRatingInfo)
249 {
250 OSTWLParentalControl* p = &(((OSTWLSettingsData*)OS_ADDR_TWL_SETTINGSDATA)->parentalControl);
251
252 if (p->flags.isSetParentalControl)
253 {
254 if (p->ogn < OS_TWL_PCTL_OGN_MAX)
255 {
256 if (appRatingInfo == NULL)
257 {
258 /* Rating information for the application to be investigated is unknown */
259 OS_TWarning("Invalid pointer to Application rating information.\n");
260 return TRUE;
261 }
262 else
263 {
264 if ((appRatingInfo[p->ogn] & OS_TWL_PCTL_OGNINFO_ENABLE_MASK) == 0)
265 {
266 /* Rating information of the research group corresponding to the application is undefined */
267 OS_TWarning("Application doesn't have rating information for the organization.\n");
268 return TRUE;
269 }
270 else
271 {
272 if ((appRatingInfo[p->ogn] & OS_TWL_PCTL_OGNINFO_ALWAYS_MASK) != 0)
273 {
274 return TRUE;
275 }
276 else
277 {
278 if ((appRatingInfo[p->ogn] & OS_TWL_PCTL_OGNINFO_AGE_MASK) > p->ratingAge)
279 {
280 return TRUE;
281 }
282 }
283 }
284 }
285 }
286 else
287 {
288 /* Research group specification in the system configuration was unexpected */
289 OS_TWarning("Invalid rating organization index (%d) in LCFG.\n", p->ogn);
290 }
291 }
292 return FALSE;
293 }
294 /* The code above is located in the TWL extended memory region */
295 #ifdef SDK_TWL
296 #include <twl/ltdmain_end.h>
297 #endif
298
299 BOOL
OS_IsParentalControledApp(u8 * appRatingInfo)300 OS_IsParentalControledApp(u8* appRatingInfo)
301 {
302 if (OS_IsRunOnTwl() == TRUE)
303 {
304 return OSi_IsParentalControledAppCore(appRatingInfo);
305 }
306 return FALSE;
307 }
308
309 /*---------------------------------------------------------------------------*
310 Name: OS_GetMovableUniqueID
311
312 Description: Gets a unique ID (included in the HW information) that can be moved between systems.
313
314 Arguments: pUniqueID: Storage destination (OS_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN bytes are stored)
315 (When not running in TWL, always fill with 0)
316
317 Returns: None.
318 *---------------------------------------------------------------------------*/
OS_GetMovableUniqueID(u8 * pUniqueID)319 void OS_GetMovableUniqueID(u8 *pUniqueID)
320 {
321 OSTWLHWNormalInfo *p;
322 if( OS_IsRunOnTwl() )
323 {
324 p = (OSTWLHWNormalInfo*)OS_ADDR_TWL_HWNORMALINFO;
325 MI_CpuCopy8( p->movableUniqueID, pUniqueID, OS_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN*sizeof(u8) );
326 }
327 else
328 {
329 MI_CpuFill8( pUniqueID, 0, OS_TWL_HWINFO_MOVABLE_UNIQUE_ID_LEN*sizeof(u8) );
330 }
331 }
332
333 /*---------------------------------------------------------------------------*
334 Name: OS_GetValidLanguageBitmap
335
336 Description: Gets the bit map of the corresponding language
337
338 Arguments: None.
339 Returns: Returns the bit map of the corresponding language
340 Return 0 when not running in TWL
341 *---------------------------------------------------------------------------*/
OS_GetValidLanguageBitmap(void)342 u32 OS_GetValidLanguageBitmap( void )
343 {
344 OSTWLHWSecureInfo *p;
345 if( OS_IsRunOnTwl() )
346 {
347 p = (OSTWLHWSecureInfo*)HW_HW_SECURE_INFO;
348 return p->validLanguageBitmap;
349 }
350 else
351 {
352 return 0;
353 }
354 }
355
356 /*---------------------------------------------------------------------------*
357 Name: OS_GetUniqueIDPtr
358
359 Description: Gets a pointer to the unique ID (included in the HW information) that can be moved between systems.
360
361 Arguments: None.
362
363 Returns: Return the pointer.
364 Return NULL when not running in TWL.
365 *---------------------------------------------------------------------------*/
OS_GetMovableUniqueIDPtr(void)366 const u8* OS_GetMovableUniqueIDPtr(void)
367 {
368 OSTWLHWNormalInfo *p;
369 if( OS_IsRunOnTwl() )
370 {
371 p = (OSTWLHWNormalInfo*)OS_ADDR_TWL_HWNORMALINFO;
372 return (p->movableUniqueID);
373 }
374 else
375 {
376 return NULL;
377 }
378 }
379
380 /*---------------------------------------------------------------------------*
381 Name: OS_IsForceDisableWireless
382
383 Description: Information on whether to forcefully invalidate wireless.
384 Gets (including HW secure information)
385
386 Arguments: None.
387
388 Returns: TRUE if forcefully invalidated; FALSE when not invalidating.
389 When not running in TWL, this is always FALSE.
390 *---------------------------------------------------------------------------*/
391 #ifdef SDK_TWL
392 #include <twl/ltdmain_begin.h>
393 static BOOL OS_IsForceDisableWireless_ltdmain(void);
OS_IsForceDisableWireless_ltdmain(void)394 static BOOL OS_IsForceDisableWireless_ltdmain(void)
395 {
396 OSTWLHWSecureInfo *p;
397 p = (OSTWLHWSecureInfo*)HW_HW_SECURE_INFO;
398 return (p->flags.forceDisableWireless == 0x1);
399 }
400 #include <twl/ltdmain_end.h>
401 #endif
402
OS_IsForceDisableWireless(void)403 BOOL OS_IsForceDisableWireless(void)
404 {
405 BOOL result;
406 if( OS_IsRunOnTwl() )
407 {
408 #ifdef SDK_TWL
409 result = OS_IsForceDisableWireless_ltdmain();
410 #endif
411 }
412 else
413 {
414 result = FALSE;
415 }
416 return (result);
417 }
418
419 /*---------------------------------------------------------------------------*
420 Name: OS_GetRegion
421
422 Description: Gets the region information.
423
424 Arguments: None.
425
426 Returns: Returns the region number.
427 Always return 0 when not running in TWL .
428 *---------------------------------------------------------------------------*/
OS_GetRegion(void)429 OSTWLRegion OS_GetRegion(void)
430 {
431 OSTWLRegion result;
432 OSTWLHWSecureInfo *p;
433 if( OS_IsRunOnTwl() )
434 {
435 p = (OSTWLHWSecureInfo*)HW_HW_SECURE_INFO;
436 result = (OSTWLRegion)(p->region);
437 }
438 else
439 {
440 result = (OSTWLRegion)0;
441 }
442 return (result);
443 }
444
445 /*---------------------------------------------------------------------------*
446 Name: OS_GetSerialNo
447
448 Description: Gets the serial number.
449
450 Arguments: serialNo: Storage destination
451 OS_TWL_HWINFO_SERIALNO_LEN_MAX bytes, including the trailing end characters are stored.
452 When not running in TWL, always fill with 0
453
454 Returns: None.
455 *---------------------------------------------------------------------------*/
OS_GetSerialNo(u8 * serialNo)456 void OS_GetSerialNo(u8 *serialNo)
457 {
458 OSTWLHWSecureInfo *p;
459 if( OS_IsRunOnTwl() )
460 {
461 p = (OSTWLHWSecureInfo*)HW_HW_SECURE_INFO;
462 MI_CpuCopy8( p->serialNo, serialNo, OS_TWL_HWINFO_SERIALNO_LEN_MAX*sizeof(u8) );
463 }
464 else
465 {
466 MI_CpuFill8( serialNo, 0, OS_TWL_HWINFO_SERIALNO_LEN_MAX*sizeof(u8) );
467 }
468 }
469
470
471 /*---------------------------------------------------------------------------*
472 Name: OS_GetWirelessFirmwareData
473
474 Description: Gets pointer to data for wireless firmware.
475
476 Arguments: None.
477 Returns: Pointer to data for wireless firmware.
478 *---------------------------------------------------------------------------*/
OS_GetWirelessFirmwareData(void)479 OSTWLWirelessFirmwareData *OS_GetWirelessFirmwareData(void)
480 {
481 if( OS_IsRunOnTwl() )
482 {
483 return (OSTWLWirelessFirmwareData*)HW_PARAM_WIRELESS_FIRMWARE_DATA;
484 }
485 else
486 {
487 return NULL;
488 }
489 }
490
491
492 /*---------------------------------------------------------------------------*
493 Name: OS_GetRegionCodeA3
494
495 Description: Gets the string that corresponds to the region code used by EC/NUP.
496
497 Arguments: region: Region code
498
499 Returns: Returns pointer to string that corresponds to the region code.
500 *---------------------------------------------------------------------------*/
501 #ifdef SDK_TWL
502 #include <twl/ltdmain_begin.h>
503 static const char* OSi_GetRegionCodeA3_ltdmain(OSTWLRegion region);
OSi_GetRegionCodeA3_ltdmain(OSTWLRegion region)504 static const char* OSi_GetRegionCodeA3_ltdmain(OSTWLRegion region)
505 {
506 const char* regionList[] =
507 {
508 "JPN", // OS_TWL_REGION_JAPAN = 0, // NCL
509 "USA", // OS_TWL_REGION_AMERICA = 1, // NOA
510 "EUR", // OS_TWL_REGION_EUROPE = 2, // NOE
511 "AUS", // OS_TWL_REGION_AUSTRALIA = 3, // NAL
512 "CHN", // OS_TWL_REGION_CHINA = 4, // IQue
513 "KOR" // OS_TWL_REGION_KOREA = 5, // NOK
514 };
515
516 if (region >= sizeof(regionList)/sizeof(regionList[0]))
517 {
518 OS_TWarning("Invalide region code.(%d)", region);
519 return NULL;
520 }
521 return regionList[region];
522 }
523 #include <twl/ltdmain_end.h>
524 #endif /* SDK_TWL */
525
OS_GetRegionCodeA3(OSTWLRegion region)526 const char* OS_GetRegionCodeA3(OSTWLRegion region)
527 {
528 if( OS_IsRunOnTwl() )
529 {
530 #ifdef SDK_TWL
531 return OSi_GetRegionCodeA3_ltdmain(region);
532 #else /* SDK_TWL */
533 return NULL;
534 #endif /* SDK_TWL */
535 }
536 else
537 {
538 return NULL;
539 }
540 }
541
542 /*---------------------------------------------------------------------------*
543 Name: OS_GetISOCountryCodeA2
544
545 Description: Convert TWO independent countries and region code numbers to ISO 3166-1 alpha-2
546
547 Arguments: twlCountry: Country and region code
548
549 Returns: Returns pointer to string that corresponds to the country and region codes.
550 Returns NULL when not running in TWL.
551 *---------------------------------------------------------------------------*/
552 extern const int OSi_CountryCodeListNumEntries;
553 extern const char* OSi_CountryCodeList[];
554
OS_GetISOCountryCodeA2(u8 twlCountry)555 const char* OS_GetISOCountryCodeA2(u8 twlCountry)
556 {
557 const char* cca2 = NULL;
558 if( OS_IsRunOnTwl() )
559 {
560 #ifdef SDK_TWL
561 if (twlCountry < OSi_CountryCodeListNumEntries)
562 {
563 cca2 = OSi_CountryCodeList[twlCountry];
564 }
565 #ifndef SDK_FINALROM
566 if (!cca2)
567 {
568 OS_TWarning("Invalid country code(%d)\n", twlCountry);
569 }
570 #endif /* SDK_FINALROM */
571 #endif /* SDK_TWL */
572 return cca2;
573 }
574 else // When not running in TWL
575 {
576 return NULL;
577 }
578 }
579
580 #undef OS_TWL_COUNTRY_NAME_MAX
581
582 /*---------------------------------------------------------------------------*
583 End of file
584 *---------------------------------------------------------------------------*/
585