00001 #include "epoc-iap.h" 00002 00003 #include "er_errors.h" 00004 00005 #include <commdb.h> 00006 #include <utf.h> 00007 00008 /* 00009 !concept {:name => "Resolving AP names", 00010 :desc => "Resolving an access point name to its ID on Symbian."} 00011 */ 00012 00013 #define MAX_IAP_NAME_LENGTH KCommsDbSvrMaxFieldLength 00014 00015 static TBool FindIapByNameL(const TDesC& aIapName, TUint32& aIapId) 00016 { 00017 TBool found = EFalse; 00018 00019 CCommsDatabase* commsDb = CCommsDatabase::NewL(EDatabaseTypeIAP); 00020 CleanupStack::PushL(commsDb); 00021 00022 { 00023 CCommsDbTableView* tableView = 00024 commsDb->OpenIAPTableViewMatchingBearerSetLC(ECommDbBearerGPRS | ECommDbBearerWLAN, ECommDbConnectionDirectionOutgoing); 00025 for (TInt errCode(tableView->GotoFirstRecord()); 00026 !errCode; 00027 errCode = tableView->GotoNextRecord()) { 00028 TBuf<MAX_IAP_NAME_LENGTH> iapName; 00029 tableView->ReadTextL(TPtrC(COMMDB_NAME), iapName); 00030 if (iapName == aIapName) { 00031 tableView->ReadUintL(TPtrC(COMMDB_ID), aIapId); 00032 found = ETrue; 00033 break; 00034 } 00035 } 00036 CleanupStack::PopAndDestroy(tableView); 00037 } 00038 00039 CleanupStack::PopAndDestroy(commsDb); 00040 00041 return found; 00042 } 00043 00044 extern "C" 00045 gboolean epoc_iap_by_name(const gchar* iapName, 00046 guint32* iapId, 00047 gboolean* found, 00048 GError** error) 00049 { 00050 *found = FALSE; 00051 00052 TPtrC8 iapNameDes8((TUint8*)iapName); 00053 TBuf<MAX_IAP_NAME_LENGTH> iapNameDes; 00054 TInt errCode = CnvUtfConverter::ConvertToUnicodeFromUtf8(iapNameDes, iapNameDes8); 00055 if (errCode) { 00056 if (error) 00057 *error = gx_error_new(domain_symbian, errCode, "Unicode conversion failure on IAP name: %s (%d)", plat_error_strerror(errCode), errCode); 00058 return FALSE; 00059 } 00060 00061 TUint32 epocIapId; 00062 TRAP(errCode, *found = FindIapByNameL(iapNameDes, epocIapId)); 00063 if (errCode) { 00064 if (error) 00065 *error = gx_error_new(domain_symbian, errCode, "error resolving IAP name to ID: %s (%d)", plat_error_strerror(errCode), errCode); 00066 return FALSE; 00067 } else if (*found) { 00068 *iapId = epocIapId; 00069 } 00070 00071 return TRUE; 00072 } 00073 00074 /* 00075 !concept {:name => "Checking AP types", 00076 :desc => "Checking whether an access point with a given ID is a modem one (GSM) or not (WLAN)."} 00077 */ 00078 00079 static TBool IsModemIapL(TUint32 aIapId) 00080 { 00081 TBool res; 00082 00083 CCommsDatabase* commsDb = CCommsDatabase::NewL(EDatabaseTypeIAP); 00084 CleanupStack::PushL(commsDb); 00085 00086 { 00087 CCommsDbTableView* tableView = commsDb->OpenViewMatchingUintLC(TPtrC(IAP), TPtrC(COMMDB_ID), aIapId); 00088 // We assume exactly one matching record, but the caller may catch KErrNotFound. 00089 User::LeaveIfError(tableView->GotoFirstRecord()); 00090 TBuf<KCommsDbSvrMaxFieldLength> bearerType; 00091 tableView->ReadTextL(TPtrC(IAP_BEARER_TYPE), bearerType); 00092 _LIT(KPat, "ModemBearer"); 00093 res = (bearerType == KPat); 00094 CleanupStack::PopAndDestroy(tableView); 00095 } 00096 00097 CleanupStack::PopAndDestroy(commsDb); 00098 00099 return res; 00100 } 00101 00102 extern "C" 00103 gboolean epoc_iap_is_modem(guint32 iapId, 00104 gboolean* found, 00105 gboolean* yes, 00106 GError** error) 00107 { 00108 TBool res = EFalse; 00109 TRAPD(errCode, res = IsModemIapL(iapId)); 00110 if (errCode == KErrNotFound) { 00111 *found = FALSE; 00112 return TRUE; 00113 } else if (errCode) { 00114 if (error) 00115 *error = gx_error_new(domain_symbian, errCode, "error looking up bearer for IAP ID %u: %s (%d)", iapId, plat_error_strerror(errCode), errCode); 00116 return FALSE; 00117 } 00118 *found = TRUE; 00119 *yes = res; 00120 return TRUE; 00121 } 00122 00123 #if __DO_LOGGING__ 00124 // This function is not kind on the stack. 00125 static void LogBearerTypesL() 00126 { 00127 CCommsDatabase* commsDb = CCommsDatabase::NewL(EDatabaseTypeIAP); 00128 CleanupStack::PushL(commsDb); 00129 00130 { 00131 CCommsDbTableView* tableView = commsDb->OpenTableLC(TPtrC(IAP)); 00132 TUint32 iapId; 00133 TBuf<KCommsDbSvrMaxFieldLength> iapName; // really should reuse this 00134 TBuf8<KCommsDbSvrMaxFieldLength+1> iapName8; 00135 TBuf<KCommsDbSvrMaxFieldLength> bearerType; 00136 TBuf8<KCommsDbSvrMaxFieldLength+1> bearerType8; 00137 TBuf<KCommsDbSvrMaxFieldLength> serviceType; 00138 TBuf8<KCommsDbSvrMaxFieldLength+1> serviceType8; 00139 for (TInt errCode(tableView->GotoFirstRecord()); 00140 !errCode; 00141 errCode = tableView->GotoNextRecord()) { 00142 tableView->ReadUintL(TPtrC(COMMDB_ID), iapId); 00143 tableView->ReadTextL(TPtrC(COMMDB_NAME), iapName); 00144 iapName8.Copy(iapName); 00145 tableView->ReadTextL(TPtrC(IAP_BEARER_TYPE), bearerType); 00146 bearerType8.Copy(bearerType); 00147 tableView->ReadTextL(TPtrC(IAP_SERVICE_TYPE), serviceType); 00148 serviceType8.Copy(serviceType); 00149 logg("iap %u, '%s', bearer '%s', service '%s'", iapId, 00150 iapName8.PtrZ(), bearerType8.PtrZ(), serviceType8.PtrZ()); 00151 } 00152 CleanupStack::PopAndDestroy(tableView); 00153 } 00154 00155 CleanupStack::PopAndDestroy(commsDb); 00156 } 00157 #endif 00158 00159 extern "C" 00160 void epoc_log_bearer_types() 00161 { 00162 #if __DO_LOGGING__ 00163 TRAPD(errCode, LogBearerTypesL()); 00164 if (errCode) 00165 logg("error %d logging bearer types", errCode); 00166 #endif 00167 } 00168 00169 /** 00170 00171 epoc-iap.cpp 00172 00173 Copyright 2009 Helsinki Institute for Information Technology (HIIT) 00174 and the authors. All rights reserved. 00175 00176 Authors: Tero Hasu <tero.hasu@hut.fi> 00177 00178 Permission is hereby granted, free of charge, to any person 00179 obtaining a copy of this software and associated documentation files 00180 (the "Software"), to deal in the Software without restriction, 00181 including without limitation the rights to use, copy, modify, merge, 00182 publish, distribute, sublicense, and/or sell copies of the Software, 00183 and to permit persons to whom the Software is furnished to do so, 00184 subject to the following conditions: 00185 00186 The above copyright notice and this permission notice shall be 00187 included in all copies or substantial portions of the Software. 00188 00189 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00190 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00191 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00192 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 00193 BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 00194 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00195 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 00196 SOFTWARE. 00197 00198 **/
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:52 2011 by Doxygen 1.6.1