mrp_net.c 25.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
#ifdef __MMI_DSM_NEW__

#ifdef WIN32
#include "windows.h"
#endif
#include "MMI_Include.h"
#include "ProtocolEvents.h"
#include "custom_data_account.h"
#include "DataAccountDef.h"
#include "DataAccountGProt.h"
#include "DataAccountEnum.h"
#include "DataAccountCommon.h"
#include "DataAccountStruct.h"
#include "DataAccountProt.h"
//#include "SimDetectionDef.h"
#include "APP2SOC_STRUCT.H"
#include "soc_api.h"
#include "FileManagerGprot.h"

#include "nwinfosrvgprot.h"
#include "mrp_include.h"

#if(MTK_VERSION <= 0x0812)
#include "Mmi_msg_struct.h"
#endif

#if(MTK_VERSION >=0x0924)
#include "smsapptype.h"
#endif

#if (MTK_VERSION <= 0x0936)
#include "MMSAppProt.h"
#endif

#if (MTK_VERSION > 0x0812)
#include "Browser_api.h"
#endif
#if (MTK_VERSION <= 0x0812)
#include "wapadp.h"
#endif

#include "dataaccountcuigprot.h"

#ifndef WAP_MAX_URL_LENGTH
#define WAP_MAX_URL_LENGTH 255
#endif

extern T_DSM_DUALSIM_SET dsmDualSim;

static int32 dsmNetworHandle = UNET_INVALID_HANDLE;

int32 gDsmUseNVdataAccount = FALSE;
T_DSM_DATA_ACCOUNT gDsmDataAccount ={0};

#ifdef __MMI_DSM_WIFI_SUPPORT__
BOOL isDsmVIAWIFI = FALSE;
int32 dsmWIFIId = 0;
#endif


kal_uint8 s_dsm_app_id = 0;

#ifdef __PME_SUPPORT__
int32 pme_get_gprs_data_account(void)
{
	return DSM_NWK_ACCOUNT_ID;
}
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////


int32 mr_net_initialize(void)
{
	{
		extern void unet_ApnAL_Init(uint8 csdAccount, uint8 gprsAccount);
		unet_ApnAL_Init(MAX_DATA_ACCOUNT_GSM_LIMIT, MAX_DATA_ACCOUNT_GPRS_LIMIT);
	}

#ifndef __MR_CFG_FEATURE_SLIM__
	mr_get_gprs_info_load();
#endif

	return MR_SUCCESS;
}


int32 mr_net_terminate(void)
{
#ifndef __MR_CFG_FEATURE_SLIM__
	mr_net_gprs_info_save();
#endif
	return MR_SUCCESS;
}


void mr_net_set_protocol_event_handler(U16 eventID, PsIntFuncPtr funcPtr, MMI_BOOL isMultiHandler)
{
#if (MTK_VERSION > 0x0848)
	#if (MTK_VERSION >= 0x0936)
		mmi_frm_set_protocol_event_handler(eventID, (PsIntFuncPtr)funcPtr, isMultiHandler);
	#else
		mmi_frm_set_protocol_event_handler(eventID, (PsIntFuncPtr)funcPtr, isMultiHandler);
	#endif
#else
	 mmi_frm_set_protocol_event_handler((PsFuncPtr)funcPtr, eventID);
#endif
}


void mr_net_clear_protocol_event_handler(U16 eventID, PsIntFuncPtr funcPtr)
{
#if (MTK_VERSION > 0x0848)
	#if (MTK_VERSION >= 0x0936)
	mmi_frm_clear_protocol_event_handler(eventID, (PsIntFuncPtr)funcPtr);
	#else
	mmi_frm_clear_protocol_event_handler(eventID, (PsIntFuncPtr)funcPtr);
	#endif
#else
	mmi_frm_clear_protocol_event_handler(eventID);
#endif
}


/****************************************************************************
函数名: int32 dsm_getUnetActSimId(void)
描  述:  获取当前sim id
参  数: voids
返  回: sim id(for unet)
****************************************************************************/
static int32 dsm_getUnetActSimId(void)
{
#if 0
	return mr_sim_get_active() == DSM_SLAVE_SIM? UNET_SIM_SLAVE : UNET_SIM_MASTER;
#else
	return (-mr_sim_get_active()) - 1;
#endif
}


int32 mr_initNetwork(MR_INIT_NETWORK_CB cb, const char *mode)
{
	mmi_ps_set_gprs_data_account_req_struct *myMsgPtr;
	U8	ref_count;
	U16	msg_len;
	MYQUEUE Message;
	U8 i=0;	
	const char* apnMode = mode != NULL ? mode : "cmnet";
	char* plmn;
	int32 plmn_len;
	T_DSM_APN *mApn=NULL;
	
	mr_net_get_network_plmn((uint8**)&plmn, &plmn_len);

#ifdef MMI_ON_HARDWARE_P	
	kal_prompt_trace(MOD_MMI,"mr_initNetwork() apn = %s",apnMode);
	kal_prompt_trace(MOD_MMI,"gDsmUseNVdataAccount=%d",gDsmUseNVdataAccount);
#endif

	// 这个提到前边,有些应用可能会没关闭网络就再初始化网络
	if(dsmNetworHandle != UNET_INVALID_HANDLE)
	{
		unet_ApnAL_CloseCntx(&dsmNetworHandle);//temp.maybe del. unet_ApnAl_ActiveCntx()中有保护
	}
	
#ifdef __MMI_DSM_WIFI_SUPPORT__
	if(isDsmVIAWIFI)//if (srv_dtcnt_wlan_state() == SRV_DTCNT_WLAN_STATE_CONNECTED)
	{
		dsmNetworHandle = UNET_SPEC_WIFI_HANDLE;
		return unet_ApnAL_ActiveCntx((char *)"WIFI", NULL, cb, dsm_getUnetActSimId(), &dsmNetworHandle); 
	}
#endif

#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	if(gDsmUseNVdataAccount)
	{
		return unet_ApnAl_ActiveCntx_Cust(cb, dsm_getUnetActSimId(), &dsmNetworHandle);
	}
	else 
#endif

	if(strncmp(plmn, "460", 3) != 0)
	{
		int32 len;
		unsigned char *netId = NULL;
		T_DSM_APN *pApn=NULL;		
		mr_net_get_network_plmn(&netId, &len);

#if !defined(WIN32) && defined(__MR_CFG_FEATURE_OVERSEA__)
		pApn = mr_getAPN(netId);
#endif
		

		if(pApn == NULL)
		{
			return MR_FAILED;
		}
		else
		{
			t_unet_apn_account account ={0};
			account.authentication_type = pApn->authentication_type;
			memcpy(account.dns ,pApn->dns,4);
			account.passWord = pApn->passWord;
			account.userName = pApn->userName;
			mr_trace("mr_initNetwork:plmn =%s apn=%s",plmn,pApn->apn);
			
			return unet_ApnAL_ActiveCntx((char*)pApn->apn, &account, cb, dsm_getUnetActSimId(), &dsmNetworHandle);
		}
		
	}
	return unet_ApnAL_ActiveCntx((char *)apnMode,NULL, cb, dsm_getUnetActSimId(), &dsmNetworHandle);
}


int32 mr_getHostByName(const char *name, MR_GET_HOST_CB cb)
{
	return unet_Soc_GetHostByName(name, cb, dsmNetworHandle);
}


int32 mr_socket(int32 type, int32 protocol)
{
	return unet_Soc_Create(type, protocol, dsmNetworHandle);
 }


int32 mr_connect(int32 s, int32 ip, uint16 port, int32 type)
{
	return unet_Soc_Connect(s, ip, port, type);
}


int32 mr_closeSocket(int32 s)
{
	return unet_Soc_Close(s);
}


int32 mr_network_socket_closeall(void)
{
	{
		extern void unet_Soc_CloseAll(void);
		unet_Soc_CloseAll();
        }

	return MR_SUCCESS;
}


int32 mr_net_socket_breakall(void)
{
	unet_Soc_Break(dsmNetworHandle);

	return MR_SUCCESS;
}


int32 mr_recv (int32 s, char *buf, int len)
{
	return unet_Soc_Recv(s, buf, len);
}


int32 mr_send(int32 s, const char *buf, int len)
{
	return unet_Soc_Send(s, buf, len);
}


int32 mr_sendto(int32 s, const char *buf, int len, int32 ip, uint16 port)
{
	return unet_Soc_Sendto(s, buf, len,ip,port);
}


int32 mr_recvfrom(int32 s, char *buf, int len, int32 *ip, uint16 *port)
{
	return unet_Soc_Recvfrom(s, buf, len,ip,port);
}


int32 mr_closeNetwork(void)
{
#ifdef __MMI_DSM_WIFI_SUPPORT__
	isDsmVIAWIFI = FALSE;
#endif	
	
	mr_network_socket_closeall();

	return unet_ApnAL_CloseCntx(&dsmNetworHandle);
}


int32 mr_net_check_connect(int32 param)
{
	return unet_Soc_State(param);
}


int32 mr_net_soc_bind(mr_bind_st *d_bind)
{
	return unet_Soc_Bind(d_bind);	
}

int dsm_data_account_save(const T_DSM_DATA_ACCOUNT* account)
{
	int drv;
	int file;
	WCHAR name[20] = L"C:\\unet_account.dat";
	UINT written = 0;
	
	drv = MMI_SYSTEM_DRV;

	if (drv < 0) return MR_FAILED;

	name[0] = drv;
	
	file = FS_Open(name, FS_READ_WRITE | FS_CREATE_ALWAYS);

	if (file < 0) return MR_FAILED;

	FS_Write(file, (void*)account, sizeof(T_DSM_DATA_ACCOUNT), &written);
	FS_Close(file);

	return MR_SUCCESS;
}


int dsm_data_account_get(T_DSM_DATA_ACCOUNT* account)
{
	int drv;
	int file;
	WCHAR name[20] = L"C:\\unet_account.dat";
	UINT read = 0;
	
	drv = MMI_SYSTEM_DRV;

	if (drv < 0) return MR_FAILED;

	name[0] = drv;
	
	file = FS_Open(name, FS_READ_ONLY);

	if (file < 0) return MR_FAILED;

	FS_Read(file, account, sizeof(T_DSM_DATA_ACCOUNT), &read);
	FS_Close(file);

	return MR_SUCCESS;
}

static void dsmSetDataAccountRsp(void *info)
{
	mr_event(MR_DATA_ACCOUNT_EVENT, MR_DATA_ACCOUNT_OP_SET, (int32)info);
}


int32 mr_net_set_data_account(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	int32 ret;

	ret = dsm_data_account_save((T_DSM_DATA_ACCOUNT*)input);
	gui_start_timer_ex(100, dsmSetDataAccountRsp, (void*)ret);
	return MR_WAITING;
#else
	return MR_IGNORE;
#endif
}


static void dsmGetDataAccountRsp(void *para)
{
	int32 ret;

	ret = dsm_data_account_get(&gDsmDataAccount);
	mr_event(MR_DATA_ACCOUNT_EVENT, MR_DATA_ACCOUNT_OP_GET, ret);
}


int32 mr_net_get_data_account_req(int32 param)
{
#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	gui_start_timer_ex(100, dsmGetDataAccountRsp, 0);
	return MR_WAITING;
#else
	return MR_IGNORE;
#endif
}

#ifndef MT6250D//huangsunbo 20120803 for mtk 6250D
static mmi_id dsm_dtcnt_cui_id = GRP_ID_INVALID;
static mmi_ret dsm_prof_proc(mmi_event_struct* evt)
{
	cui_dtcnt_select_event_struct* dtcnt_select_event;
	
	switch (evt->evt_id)
	{
		case CUI_DTCNT_SELECT_EVENT_RESULT_OK:
		{
			cbm_sim_id_enum cbm_sim_id;
			kal_uint8 cbm_app_id;
			kal_bool always_ask;
			kal_uint32 ori_acct_id;
			srv_dtcnt_store_prof_data_struct prof_data;
			srv_dtcnt_prof_gprs_struct prof_gprs;
			T_DSM_DATA_ACCOUNT dsm_account;
			int i;
			
			dtcnt_select_event = (cui_dtcnt_select_event_struct*)evt;

			cbm_decode_data_account_id(dtcnt_select_event->account_id, &cbm_sim_id,
                                       &cbm_app_id, &always_ask, &ori_acct_id);

			prof_data.prof_data = &prof_gprs;
			prof_data.prof_fields = SRV_DTCNT_PROF_FIELD_ALL;
			prof_data.prof_type = SRV_DTCNT_BEARER_GPRS;
			if (srv_dtcnt_store_qry_prof(ori_acct_id, &prof_data) == SRV_DTCNT_RESULT_SUCCESS)
			{
				memset(&dsm_account, 0, sizeof(T_DSM_DATA_ACCOUNT));
				dsm_account.authentication_type = prof_gprs.prof_common_header.Auth_info.AuthType;
				strcpy((char*)dsm_account.user_name, (char*)prof_gprs.prof_common_header.Auth_info.UserName);
				strcpy ((char*)dsm_account.password, (char*)prof_gprs.prof_common_header.Auth_info.Passwd);
				for ( i = 0; i < 4; i++) {
					dsm_account.dns[i] = prof_gprs.prof_common_header.PrimaryAddr[i];
				}
				strcpy((char*)dsm_account.apn, (char*)prof_gprs.APN);
				dsm_data_account_save(&dsm_account);
			}

			cui_dtcnt_select_close(dsm_dtcnt_cui_id);
			dsm_dtcnt_cui_id = GRP_ID_INVALID;

			break;
		}

		case CUI_DTCNT_SELECT_EVENT_RESULT_CANCEL:
		case CUI_DTCNT_SELECT_EVENT_RESULT_FAILED:
		case CUI_DTCNT_SELECT_EVENT_CLOSE:
		{
			cui_dtcnt_select_close(dsm_dtcnt_cui_id);
			dsm_dtcnt_cui_id = GRP_ID_INVALID;
			
			break;
		}
	}
		
	return MMI_RET_OK;
}


void dsmMtkUISetDataAccount(void)
{
	cui_dtcnt_select_run_struct cui_param;
	
	mmi_frm_group_create(GRP_ID_ROOT, GRP_ID_MYTHROAD, dsm_prof_proc, NULL);
	mmi_frm_group_enter(GRP_ID_MYTHROAD, MMI_FRM_NODE_SMART_CLOSE_FLAG);

	//dsm_dtcnt_cui_id = cui_dtcnt_select_create(mmi_frm_group_get_active_id());
	dsm_dtcnt_cui_id = cui_dtcnt_select_create(GRP_ID_MYTHROAD);
	kal_prompt_trace(MOD_MMI, "#####dsm_dtcnt_cui_id=%d", dsm_dtcnt_cui_id);
	if (dsm_dtcnt_cui_id == GRP_ID_INVALID)
	{
		//mmi_frm_group_close(GRP_ID_MYTHROAD);
		return;
	}

	memset(&cui_param, 0, sizeof(cui_dtcnt_select_run_struct));
	cui_param.bearers = DATA_ACCOUNT_BEARER_GPRS;
	cui_param.app_id = 0;
	cui_param.AppMenuID = SERVICES_WAP_MENU_ID;
	cui_param.option = 0;	// 这个参数必须为0,否则会把所有SIM卡的账号显示出来
	cui_param.type = CUI_DTCNT_SELECT_TYPE_NORMAL;
	cui_param.sim_selection = -mr_sim_get_active() - 1;	
	cui_dtcnt_select_set_param(dsm_dtcnt_cui_id, &cui_param);

	cui_dtcnt_select_run(dsm_dtcnt_cui_id);
}
#else
#include "MMI_features.h"
#include "MMIDataType.h"
#include "GlobalResDef.h"
#include "wgui_categories_util.h"
#include "wgui_categories_inputs.h"
#include "GlobalConstants.h"
#include "wgui_categories_list.h"
#include "CommonScreens.h"
#include "wgui_categories_text_viewer.h"
#include "InlineCuiGprot.h"
#include "mmi_rp_app_dataaccount_def.h"
#include "DataAccountProt.h"

static const cui_inline_item_caption_struct apn_caption = {STR_ID_DTCNT_GPRS_APN};
static const cui_inline_item_text_edit_struct apn_textedit = 
{
    0,
    0,
    MAX_GPRS_MMI_APN_LEN + 1,
    IMM_INPUT_TYPE_ASCII_CHAR,
    0,
    NULL
};

static const cui_inline_item_caption_struct username_caption = {STR_GLOBAL_USERNAME};
static const cui_inline_item_text_edit_struct username_textedit = 
{
    0,
    0,
    MAX_USER_LEN + 1,
    IMM_INPUT_TYPE_ASCII_CHAR,
    0,
    NULL
};

static const cui_inline_item_caption_struct passwd_caption = {STR_GLOBAL_PASSWORD};
static const cui_inline_item_text_edit_struct passwd_textedit = 
{
    0,
    0,
    MAX_PASSWD_LEN + 1,
    IMM_INPUT_TYPE_ASCII_PASSWORD,
    0,
    NULL
};

static const MMI_STR_ID auth_type_sel_str[] = 
{
    STR_GLOBAL_NORMAL,
    STR_ID_DTCNT_GPRS_CHAP_AUTH
};

static const cui_inline_item_caption_struct auth_type_caption = {STR_ID_DTCNT_GPRS_AUTH_TYP};
static const cui_inline_item_select_struct auth_type_select = 
{
    sizeof(auth_type_sel_str)/sizeof(auth_type_sel_str[0]),
    0,
    auth_type_sel_str
};

static const cui_inline_item_caption_struct dns_address1_caption = {STR_ID_DTCNT_DNS_ADDRESS1};
static const cui_inline_item_ip4_struct dns_address1_ip4 = {0, 0, 0, 0};

static const cui_inline_set_item_struct gprs_common_inline_edit_items[] =
{
	{COMMON_ADDR_CAPTION_ID, CUI_INLINE_ITEM_TYPE_CAPTION, IMG_GLOBAL_L2, (void*)&apn_caption},
	{COMMON_ADDR_TEXTEDIT_ID, CUI_INLINE_ITEM_TYPE_TEXT_EDIT, 0, (void*)&apn_textedit},
	{COMMON_USERNAME_CAPTION_ID, CUI_INLINE_ITEM_TYPE_CAPTION, IMG_GLOBAL_L3, (void*)&username_caption},
	{COMMON_USERNAME_TEXTEDIT_ID, CUI_INLINE_ITEM_TYPE_TEXT_EDIT, 0, (void*)&username_textedit},
	{COMMON_PASSWD_CAPTION_ID, CUI_INLINE_ITEM_TYPE_CAPTION, IMG_GLOBAL_L4, (void*)&passwd_caption},
	{COMMON_PASSWD_TEXTEDIT_ID, CUI_INLINE_ITEM_TYPE_TEXT_EDIT, 0, (void*)&passwd_textedit},
	{GPRS_AUTH_CAPTION_ID, CUI_INLINE_ITEM_TYPE_CAPTION, IMG_GLOBAL_L5, (void*)&auth_type_caption},
	{GPRS_AUTH_SELECT_ID, CUI_INLINE_ITEM_TYPE_SELECT, 0, (void*)&auth_type_select},
	{ADVANCED_DNS1_CAPTION_ID, CUI_INLINE_ITEM_TYPE_CAPTION, IMG_GLOBAL_L8, (void*)&dns_address1_caption},
	{ADVANCED_DNS1_IP4_ID, CUI_INLINE_ITEM_TYPE_IP4, 0, (void*)&dns_address1_ip4},    
};

static U8 addr[MAX_DTCNT_LIST_ADDR_LEN * ENCODING_LENGTH];
static U8 password[(MAX_PASSWD_LEN + 1) * ENCODING_LENGTH];
static U8 user_name[(MAX_USER_LEN + 1) * ENCODING_LENGTH];

static mmi_ret dsm_prof_proc(mmi_event_struct* evt)
{
	cui_event_inline_abort_struct *inline_abort_event;
	cui_event_inline_submit_struct *inline_submit_event;
	S32 auth_type;
	T_DSM_DATA_ACCOUNT dsm_account = {0};

	switch (evt->evt_id)
	{
		case EVT_ID_CUI_INLINE_SUBMIT:
		{
			inline_submit_event = (cui_event_inline_submit_struct*)evt;

			memset(addr, 0, sizeof(addr));
			memset(password, 0, sizeof(password));
			memset(user_name, 0, sizeof(user_name));

			cui_inline_get_value(inline_submit_event->sender_id, COMMON_ADDR_TEXTEDIT_ID, addr);

			if (mmi_ucs2strlen(addr) != 0)
			{
				cui_inline_get_value(inline_submit_event->sender_id, COMMON_USERNAME_TEXTEDIT_ID, user_name);
				cui_inline_get_value(inline_submit_event->sender_id, COMMON_PASSWD_TEXTEDIT_ID, password);
				cui_inline_get_value(inline_submit_event->sender_id, GPRS_AUTH_SELECT_ID, &auth_type);
				cui_inline_get_value(inline_submit_event->sender_id, ADVANCED_DNS1_IP4_ID, &dsm_account.dns);

				mmi_ucs2_to_asc((CHAR*)dsm_account.apn, (CHAR*)addr);
				mmi_ucs2_to_asc((CHAR*)dsm_account.user_name, (CHAR*)user_name);
				mmi_ucs2_to_asc((CHAR*)dsm_account.password, (CHAR*)password);
				dsm_account.authentication_type = auth_type;

				dsm_data_account_save(&dsm_account);
			}

			cui_inline_close(inline_submit_event->sender_id);

			break;
		}

		case EVT_ID_CUI_INLINE_ABORT:
		{
			inline_abort_event = (cui_event_inline_abort_struct*)evt;

			cui_inline_close(inline_abort_event->sender_id);
			
			break;
		}
	}

	return MMI_RET_OK;
}

void dsmMtkUISetDataAccount(void)
{	
	mmi_id dsm_dtcnt_cui_id = GRP_ID_INVALID;
	cui_inline_struct common_inline_struct = {0};
	T_DSM_DATA_ACCOUNT account = {0};
	int i;
		
	mmi_frm_group_create(GRP_ID_ROOT, GRP_ID_MYTHROAD, dsm_prof_proc, NULL);
	mmi_frm_group_enter(GRP_ID_MYTHROAD, MMI_FRM_NODE_SMART_CLOSE_FLAG);

	common_inline_struct.title = STR_GLOBAL_EDIT;
	//common_inline_struct.title_icon = GetRootTitleIcon(SERVICES_DATA_CONNECT_MAIN_MENU_ID);
	common_inline_struct.screen_flag = CUI_INLINE_SCREEN_LOOP | CUI_INLINE_SCREEN_DISABLE_DONE;
	common_inline_struct.items_count = sizeof(gprs_common_inline_edit_items) / sizeof(gprs_common_inline_edit_items[0]);
	common_inline_struct.items = gprs_common_inline_edit_items;

	dsm_dtcnt_cui_id = cui_inline_create(GRP_ID_MYTHROAD, &common_inline_struct);
	if (dsm_dtcnt_cui_id == GRP_ID_INVALID)
		return;

	dsm_data_account_get(&account);

	memset(addr, 0, sizeof(addr));
	memset(password, 0, sizeof(password));
	memset(user_name, 0, sizeof(user_name));

	mmi_asc_to_ucs2((CHAR*)addr, (CHAR*)account.apn);
	mmi_asc_to_ucs2((CHAR*)user_name, (CHAR*)account.user_name);
	mmi_asc_to_ucs2((CHAR*)password, (CHAR*)account.password);
	
	cui_inline_set_value(dsm_dtcnt_cui_id, COMMON_ADDR_TEXTEDIT_ID, addr);
	cui_inline_set_value(dsm_dtcnt_cui_id, COMMON_USERNAME_TEXTEDIT_ID, user_name);
	cui_inline_set_value(dsm_dtcnt_cui_id, COMMON_PASSWD_TEXTEDIT_ID, password);
	cui_inline_set_value(dsm_dtcnt_cui_id, GPRS_AUTH_SELECT_ID, (void*)account.authentication_type);
	cui_inline_set_value(dsm_dtcnt_cui_id, ADVANCED_DNS1_IP4_ID, account.dns); 
            
	cui_inline_run(dsm_dtcnt_cui_id);
}
#endif//MT6250D END

static void mr_connectWAP_cb(void* url)
{
#ifdef BROWSER_SUPPORT
	wap_start_browser(WAP_BROWSER_GOTO_URL,(uint8*)url);
#endif	
}

void mr_connectWAP(char* wap)
{
#ifdef BROWSER_SUPPORT
	static int8 url[(WAP_MAX_URL_LENGTH + 1) * 2] = {0};
	
	if(wap == NULL || strlen(wap) == 0 || strlen(wap) > WAP_MAX_URL_LENGTH)
	{
		return;
	}
	
	mmi_asc_to_ucs2((CHAR*)url, wap);
	gui_start_timer_ex(100, mr_connectWAP_cb, url);
#endif	
}


static int32 mr_net_get_network_id_from_plmn(char* plmn)
{
#ifdef MMI_ON_HARDWARE_P
	if (memcmp((char *)plmn,"46002", 5) == 0
		|| memcmp((char *)plmn,"46000", 5) == 0
		|| memcmp((char *)plmn,"46007", 5) == 0)//中国移动网络码
	{
		return MR_NET_ID_MOBILE;
	} 
	else if(memcmp((char *)plmn, "46001", 5)==0)//中国联通
	{
		return MR_NET_ID_CN;
	} 
	else if(memcmp((char *)plmn, "46003", 5) == 0)//中国电信
	{
		return MR_NET_ID_CDMA;
	}
#endif

	return MR_NET_ID_OTHER;
}

int32 mr_getNetworkID(void)
{
	mmi_sim_enum sim;
	srv_nw_info_service_availability_enum nw_info_service;
	int32 dsm_sim;
	char plmn[SRV_MAX_PLMN_LEN + 1];

	sim = mr_sim_active_id_dsm2mmi();

	nw_info_service = srv_nw_info_get_service_availability(sim);

	if (nw_info_service != SRV_NW_INFO_SA_FULL_SERVICE)
	{
		return MR_NET_ID_NONE;
	}

	if (!srv_nw_info_get_nw_plmn(sim, plmn, sizeof(plmn)))
	{
		return MR_NET_ID_NONE;
	}

	return mr_net_get_network_id_from_plmn(plmn);
}


int32 mr_net_get_network_plmn(uint8**output,int32 *output_len)
{
	mmi_sim_enum sim;
	int32 dsm_sim;
	static char plmn[SRV_MAX_PLMN_LEN + 1];

	sim = mr_sim_active_id_dsm2mmi();

	memset(plmn, 0, sizeof(plmn));
	if (srv_nw_info_get_nw_plmn(sim, plmn, sizeof(plmn)))
	{
		*output = (uint8*)plmn;
		*output_len = SRV_MAX_PLMN_LEN;
		
		return MR_SUCCESS;
	}
	else
	{
		return MR_FAILED;
	}
}


int32 mr_net_data_account_set_use_flag(int32 param)
{
#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	extern int32 gDsmUseNVdataAccount;
	if(param)
	{
		gDsmUseNVdataAccount = 0;
	}
	else
	{
		gDsmUseNVdataAccount = 1; 
	}
	return MR_SUCCESS;
#else
	return MR_IGNORE;
#endif
}


int32 mr_net_data_account_show_ui(int32 param)
{
#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	dsmMtkUISetDataAccount();
	return MR_SUCCESS;
#else
	return MR_IGNORE;
#endif
}


int32 mr_net_get_data_account(uint8* input, int32 input_len, uint8** output, int32* output_len, MR_PLAT_EX_CB *cb)
{
#if !defined(__MR_CFG_FEATURE_SLIM__) || defined(__MR_CFG_FEATURE_OVERSEA__)
	if(output == NULL||output_len == NULL)
		return MR_FAILED;
	*output = (uint8 *)&gDsmDataAccount;
	*output_len = sizeof(gDsmDataAccount);
	return MR_SUCCESS;
#else
	return MR_IGNORE;
#endif
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef __MR_CFG_FEATURE_SLIM__

typedef struct {
	char imsi[MAX_IMSI_LEN];
	mr_datetime timestamp;
}mr_net_gprs_info_t;

extern char gIMSI[];
#ifdef __MMI_DUAL_SIM_MASTER__		
static mr_net_gprs_info_t  g_gprs_info[2];
extern char gIMSI_2[];
#else
static mr_net_gprs_info_t  g_gprs_info[1];
#endif

void mr_get_gprs_info_load(void)
{
	if(g_gprs_info[0].timestamp.year == 0 
#ifdef __MMI_DUAL_SIM_MASTER__				
		&& g_gprs_info[1].timestamp.year == 0
#endif		
		)
	{
		U16 path[DSM_MAX_FILE_LEN];
		FS_HANDLE fd;
		UINT readBytes;
		
		kal_wsprintf(path, "%c:\\%s\\gprs.cfg", __MR_CFG_VAR_ROOT_DRV__, __MR_CFG_VAR_ROOT_PATH__);
		fd = FS_Open((WCHAR *)path, FS_READ_ONLY);
		if(fd <= 0) return;
		
		FS_Read(fd, &g_gprs_info, sizeof(g_gprs_info), &readBytes);
		FS_Close(fd);
	}

	mr_trace("mr_get_gprs_info_load: %s, %d, %s, %d", g_gprs_info[0].imsi, g_gprs_info[0].timestamp.year, g_gprs_info[1].imsi, g_gprs_info[1].timestamp.year);
}


void mr_net_gprs_info_save(void)
{
	if(g_gprs_info[0].timestamp.year 
#ifdef __MMI_DUAL_SIM_MASTER__				
		|| g_gprs_info[1].timestamp.year
#endif		
		)
	{
		U16 path[DSM_MAX_FILE_LEN];
		FS_HANDLE fd;
		UINT writeBytes;
		
		kal_wsprintf(path, "%c:\\%s\\gprs.cfg", __MR_CFG_VAR_ROOT_DRV__, __MR_CFG_VAR_ROOT_PATH__);
		fd = FS_Open((WCHAR *)path, FS_READ_WRITE | FS_CREATE);
		FS_Write(fd, &g_gprs_info, sizeof(g_gprs_info), &writeBytes);
		FS_Close(fd);
	}

	mr_trace("mr_net_gprs_info_save: %s, %d, %s, %d", g_gprs_info[0].imsi, g_gprs_info[0].timestamp.year, g_gprs_info[1].imsi, g_gprs_info[1].timestamp.year);
}


int32 mr_net_gprs_info_query(uint8 * input, int32 input_len, uint8 * * output, int32 * output_len, MR_PLAT_EX_CB * cb)
{
	if(!input || input_len != sizeof(mr_datetime))
		return MR_FAILED;

	if(mr_sim_get_active() == DSM_MASTER_SIM)
	{
		mr_trace("mr_net_gprs_info_query0: %s, %d, %d, %d", g_gprs_info[0].imsi, 
			g_gprs_info[0].timestamp.year, g_gprs_info[0].timestamp.month, g_gprs_info[0].timestamp.day);	
		
		if(strncmp(g_gprs_info[0].imsi, gIMSI, MAX_IMSI_LEN) == 0){
			memcpy(input, &g_gprs_info[0].timestamp, sizeof(mr_datetime));
			return MR_SUCCESS;
		}
	}else{
#ifdef __MMI_DUAL_SIM_MASTER__		
		mr_trace("mr_net_gprs_info_query1: %s, %d, %d, %d", g_gprs_info[0].imsi, 
			g_gprs_info[0].timestamp.year, g_gprs_info[0].timestamp.month, g_gprs_info[0].timestamp.day);	

		if(strncmp(g_gprs_info[1].imsi, gIMSI_2, MAX_IMSI_LEN) == 0){
			memcpy(input, &g_gprs_info[1].timestamp, sizeof(mr_datetime));
			return MR_SUCCESS;
		}
#endif
	}
	
	return MR_FAILED;
}


void mr_net_gprs_info_update(void)
{
	if(mr_sim_get_active() == DSM_MASTER_SIM)
	{
		memcpy(g_gprs_info[0].imsi, gIMSI, MAX_IMSI_LEN);
		mr_getDatetime(&g_gprs_info[0].timestamp);
		mr_trace("mr_net_gprs_info_update0: %s, %d, %d, %d", g_gprs_info[0].imsi, 
			g_gprs_info[0].timestamp.year, g_gprs_info[0].timestamp.month, g_gprs_info[0].timestamp.day);	
	}else{
#ifdef __MMI_DUAL_SIM_MASTER__	
		memcpy(g_gprs_info[1].imsi, gIMSI_2, MAX_IMSI_LEN);
		mr_getDatetime(&g_gprs_info[1].timestamp);
		mr_trace("mr_net_gprs_info_update1: %s, %d, %d, %d", g_gprs_info[1].imsi, 
			g_gprs_info[1].timestamp.year, g_gprs_info[1].timestamp.month, g_gprs_info[1].timestamp.day);	
#endif		
	}

#ifndef __MR_CFG_FEATURE_SLIM__
	mr_backstage_update_status_icons();
#endif
}
#endif

#if 0//def __MR_CFG_FEATURE_SLIM__//默认使用全语言版本,huangsunbo 20111117
#define GET_APN(X)     pApn=(T_DSM_APN*)mr_getAPN##X(netId)

T_DSM_APN *mr_getAPN(unsigned char * netId)
{
#ifndef WIN32
	T_DSM_APN *pApn = NULL;
	if(
	(GET_APN(CHINESE))
	||(GET_APN(AFRICA))
	||(GET_APN(ASIA))
	||(GET_APN(EUROPE))
#if defined( __MMI_LANG_TR_CHINESE__)
	 ||(GET_APN(TR_CHINESE))
#endif

#if defined( __MMI_LANG_SPANISH__)
	 ||(GET_APN(SPANISH))
#endif

#if defined(__MMI_LANG_DANISH__)
	 ||(GET_APN(DANISH))
#endif

#if  defined(__MMI_LANG_POLISH__)
      	 ||(GET_APN(POLISH))
#endif
#if  defined(__MMI_LANG_FRENCH__)
        ||(GET_APN(FRENCH))
#endif

#if  defined(__MMI_LANG_GERMAN__)
      ||(GET_APN(GERMAN))
#endif

#if  defined(__MMI_LANG_ITALIAN__)
       ||(GET_APN(ITALIAN))
#endif

#if  defined(__MMI_LANG_THAI__)
       ||(GET_APN(THAI))
#endif

#if  defined(__MMI_LANG_RUSSIAN__)
      ||(GET_APN(RUSSIAN))
#endif

#if  defined(__MMI_LANG_BULGARIAN__)
       ||(GET_APN(BULGARIAN))
#endif

#if  defined(__MMI_LANG_UKRAINIAN__)
       ||(GET_APN(UKRAINIAN))
#endif

#if  defined(__MMI_LANG_PORTUGUESE__)
       ||(GET_APN(PORTUGUESE))
#endif

#if  defined(__MMI_LANG_TURKISH__)
       ||(GET_APN(TURKISH))
#endif

#if  defined(__MMI_LANG_VIETNAMESE__)
       ||(GET_APN(VIETNAMESE))
#endif

#if  defined(__MMI_LANG_INDONESIAN__)
       ||(GET_APN(INDONESIAN))
#endif

#if  defined(__MMI_LANG_CZECH__)
       ||(GET_APN(CZECH))
#endif

#if  defined(__MMI_LANG_MALAY__)
       ||(GET_APN(MALAY))
#endif

#if  defined(__MMI_LANG_FINNISH__)
      ||(GET_APN(FINNISH))
#endif

#if  defined(__MMI_LANG_HUNGARIAN__)
       ||(GET_APN(HUNGARIAN))
#endif

#if  defined(__MMI_LANG_SLOVAK__)
       ||(GET_APN(SLOVAK))
#endif

#if  defined(__MMI_LANG_DUTCH__)
       ||(GET_APN(DUTCH))
#endif

#if  defined(__MMI_LANG_NORWEGIAN__)
       ||(GET_APN(NORWEGIAN))
#endif

#if  defined(__MMI_LANG_SWEDISH__)
       ||(GET_APN(SWEDISH))
#endif

#if  defined(__MMI_LANG_CROATIAN__)
      ||(GET_APN(CROATIAN))
#endif

#if  defined(__MMI_LANG_ROMANIAN__)
      ||(GET_APN(ROMANIAN))
#endif

#if  defined(__MMI_LANG_SLOVENIAN__)
       ||(GET_APN(SLOVENIAN))
#endif

#if defined(__MMI_LANG_GREEK__)
       ||(GET_APN(GREEK))
#endif

#if  defined (__MMI_LANG_HEBREW__)
       ||(GET_APN(HEBREW))
#endif

#if defined (__MMI_LANG_ARABIC__)
       ||(GET_APN(ARABIC))
#endif

#if  defined (__MMI_LANG_PERSIAN__)
       ||(GET_APN(PERSIAN))
#endif

#if  defined (__MMI_LANG_URDU__)
       ||(GET_APN(URDU))
#endif

#if  defined (__MMI_LANG_HINDI__)
       ||(GET_APN(HINDI))
#endif

#if defined (__MMI_LANG_MARATHI__)
       ||(GET_APN(MARATHI))
#endif

#if  defined (__MMI_LANG_TAMIL__)
       ||(GET_APN(TAMIL))
#endif

#if  defined (__MMI_LANG_BENGALI__)
       ||(GET_APN(BENGALI))
#endif

#if defined (__MMI_LANG_PUNJABI__)
       ||(GET_APN(PUNJABI))
#endif

#if  defined (__MMI_LANG_TELUGU__)
	||(GET_APN(TELUGU))
#endif
	   )
	   	return pApn;
	else
		return NULL;
#else
	return NULL;
#endif
}
#endif

#endif