Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Regular Contributor
pgoeol
Posts: 55
Registered: ‎02-17-2010
My Carrier: Airtel

Differentiating between Direct TCP & WAP 2.0 network connections

Hi...

I've a third party application and I would like to track which network method is being used by the application.
I looked at the Event Logs (by pressing Alt L G L G) and able to distinguish between WiFi -  MDS - direct TCP network calls, but Event Logs are same for direct TCP and WAP2.0 requests.
Is it possible to identify whether the application is using WAP2.0 or Direct TCP for establishing network connection.

Thanks,
 Pulkit

Please use plain text.
Developer
peter_strange
Posts: 17,952
Registered: ‎07-14-2008

Re: Differentiating between Direct TCP & WAP 2.0 network connections

I thought direct TCP talked about a tunnel and WAP didn't.

 

What device and carrier are you looking on?  Are both options supported on it?

Please use plain text.
Regular Contributor
pgoeol
Posts: 55
Registered: ‎02-17-2010
My Carrier: Airtel

Re: Differentiating between Direct TCP & WAP 2.0 network connections

I have blackberry 9000 device and carrier is Airtel (india). I'm sure that direct TCP is supported by the carrier but how can i determine whether WAP is supported or not ???

Please use plain text.
Developer
sudhakar_koundinya
Posts: 66
Registered: ‎01-14-2010
My Carrier: Airtel

Re: Differentiating between Direct TCP & WAP 2.0 network connections

[ Edited ]

HELLO

 

Try to understand and use below code snippet. This will help you to take decision in using specific network channel

 

 

Below Code is responsible to intialize the service record instances and checks & determines network channel along with coverage info.

 

 

/** Stores transport ServiceBooks if found. Otherwise, null */
	private ServiceRecord srMDS, srBIS, srWAP, srWAP2, srWiFi, srUnite;
	/** Flags indicating the coverage status of each transport */
	private boolean coverageTCP = false, coverageMDS = false,
			coverageBIS = false, coverageWAP = false, coverageWAP2 = false,
			coverageWiFi = false, coverageUnite = false;
	private boolean fetchStarted, connected;
	// Wap fields
	private String wapGatewayIP, wapGatewayAPN, wapGatewayPort, wapSourceIP,
			wapSourcePort, wapUser, wapPassword, tcpAPN, tcpAPNUser,
			tcpAPNPassword;

	private boolean isWapEnableWTLS;


	/**
	 * Applies to WAP1.0 connection only. This is a flag to indicate if WAP
	 * parameters should be parsed from the ServiceBook. If user provides any
	 * WAP parameter on the InputScreen, this flag is set to false. TODO
	 * Currently parsing from service book is not supported.
	 */
	private boolean wapParametersUnavailable = true;

 

 

 

 

/**
	 * Initializes the ServiceRecord instances for each transport (if
	 * available). Otherwise leaves it null. Also determines if sufficient
	 * coverage is available for each transport and sets coverage* flags.
	 */
	private void initializeTransportAvailability() {
		ServiceBook sb = ServiceBook.getSB();
		ServiceRecord[] records = sb.getRecords();

		for (int i = 0; i < records.length; i++) {
			ServiceRecord myRecord = records[i];
			String cid, uid;

			if (myRecord.isValid() && !myRecord.isDisabled()) {
				cid = myRecord.getCid().toLowerCase();
				uid = myRecord.getUid().toLowerCase();
				// BIS
				if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") != -1) {
					srBIS = myRecord;
				}

				// BES
				if (cid.indexOf("ippp") != -1 && uid.indexOf("gpmds") == -1) {
					srMDS = myRecord;
				}
				// WiFi
				if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") != -1) {
					srWiFi = myRecord;
				}
				// Wap1.0
				if (getConfigType(myRecord) == CONFIG_TYPE_WAP
						&& cid.equalsIgnoreCase("wap")) {
					srWAP = myRecord;
				}
				// Wap2.0
				if (cid.indexOf("wptcp") != -1 && uid.indexOf("wifi") == -1
						&& uid.indexOf("mms") == -1) {
					srWAP2 = myRecord;
				}
				// Unite
				if (getConfigType(myRecord) == CONFIG_TYPE_BES
						&& myRecord.getName().equals(UNITE_NAME)) {
					srUnite = myRecord;
				}
			}
		}
		if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_BIS_B)) {
			coverageBIS = true;
		}
		if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_DIRECT)) {
			coverageTCP = true;
			coverageWAP = true;
			coverageWAP2 = true;
		}
		if (CoverageInfo.isCoverageSufficient(CoverageInfo.COVERAGE_MDS)) {
			coverageMDS = true;
			coverageUnite = true;
		}

		if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED) {
			coverageWiFi = true;
		}

	}

	/**
	 * Gets the config type of a ServiceRecord using getDataInt below
	 * 
	 * @param record
	 *            A ServiceRecord
	 * @return configType of the ServiceRecord
	 */
	private int getConfigType(ServiceRecord record) {
		return getDataInt(record, 12);
	}

	/**
	 * Gets the config type of a ServiceRecord. Passing 12 as type returns the
	 * configType.
	 * 
	 * @param record
	 *            A ServiceRecord
	 * @param type
	 *            dataType
	 * @return configType
	 */
	private int getDataInt(ServiceRecord record, int type) {
		DataBuffer buffer = null;
		buffer = getDataBuffer(record, type);

		if (buffer != null) {
			try {
				return ConverterUtilities.readInt(buffer);
			} catch (Throwable e) {
				return -1;
			}
		}
		return -1;
	}

	/**
	 * Utility Method for getDataInt()
	 */
	private DataBuffer getDataBuffer(ServiceRecord record, int type) {
		byte[] data = record.getApplicationData();
		if (data != null) {
			DataBuffer buffer = new DataBuffer(data, 0, data.length, true);
			try {
				buffer.readByte();
			} catch (Throwable e1) {
				return null;
			}
			if (ConverterUtilities.findType(buffer, type)) {
				return buffer;
			}
		}
		return null;
	}

	/**
	 * Populates the carrier information.
	 */
	private void populateCarrierInfo() {
		final String carrierName = RadioInfo.getCurrentNetworkName();
		;
		int mcc = -1, mnc = -1;
		CarrierInfo cinfo = null;
		CarrierInfoParser cparser = null;
		try {
			if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_CDMA) {
				String imsi = GPRSInfo.imeiToString(CDMAInfo.getIMSI());
				mcc = Integer.parseInt(imsi.substring(0, 3));
				mnc = Integer.parseInt(imsi.substring(3, 6));
			} else if (RadioInfo.getNetworkType() == RadioInfo.NETWORK_UMTS
					|| RadioInfo.getNetworkType() == RadioInfo.NETWORK_GPRS) {
				mcc = Integer.parseInt(Integer.toHexString(GPRSInfo
						.getHomeMCC()));
				mnc = Integer.parseInt(Integer.toHexString(GPRSInfo
						.getHomeMNC()));
			}
		} catch (NullPointerException npe) {

		} catch (NumberFormatException ne) {

		} catch (Throwable t) {
		}

		InputStream xmlis = null;
		try {
			FileConnection fconn = (FileConnection) Connector.open(
					"file:///store/netdiag/carrier_info.xml", Connector.READ);
			if (null != fconn)
				xmlis = fconn.openInputStream();
		} catch (Exception e) {
		}

		if (xmlis != null) {
			cparser = new CarrierInfoParser(xmlis);

			if (mcc != -1 && mnc != -1)
				cinfo = cparser.getCarrierInfo(mcc, mnc);
			else if (mcc != -1 && mnc == -1)
				cinfo = cparser.getCarrierInfo(mcc, carrierName);
			if (cinfo == null && mcc != -1)
				cinfo = cparser.getCarrierInfo(mcc, carrierName.substring(0,
						carrierName.indexOf(" ")));
		}
		if (cinfo != null) {
			cinfo.setCarrierName(carrierName);

			tcpAPN = cinfo.getTcpAPN();
			tcpAPNUser = cinfo.getTcpAPNUserName();
			tcpAPNPassword = cinfo.getTcpAPNPassword();
			wapGatewayAPN = cinfo.getWapAPN();
			wapGatewayIP = cinfo.getWapIP();
			wapGatewayPort = cinfo.getWapPort();
			wapSourceIP = cinfo.getWapSourceIP();
			wapSourcePort = cinfo.getWapSourcePort();
			wapUser = cinfo.getWapUserName();
			wapPassword = cinfo.getWapPassword();
			isWapEnableWTLS = cinfo.isEnabaleWTLS();
		}
	}

 

For calling the  wap specific functions, do have checks as mentioned below.

 

 

if (!connected && srWAP != null && coverageWAP) {
				getWAPURL();
				if (!wapParametersUnavailable) {
					doHTTPWAP();
					/** WAP1.0 usign HTTP */
					connected = true;
				}
			}
			if (!connected && srWAP2 != null && coverageWAP2) {
				doHTTPWAP2();
				/** WAP2.0 using HTTP */
				connected = true;
			}

 

 

 

 

Regards,

Sudhakar Chavali

 

 

Please use plain text.
Developer
peter_strange
Posts: 17,952
Registered: ‎07-14-2008

Re: Differentiating between Direct TCP & WAP 2.0 network connections

Thank you for your code sudhakar_koundinya - there are some interesting ideas in there, including the idea of reading in some XML configuration information from the SD Card.

 

Can I recommend that the original poster review the Network Diagnostic Tool.  It is the 'reference' when it comes to determining what capabilities a device has, and is a complete test tool that can be run on the device.  You will find it here:

 

What Is - Network Diagnostic Tool
Article Number: DB-00684

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

Please use plain text.
Regular Contributor
pgoeol
Posts: 55
Registered: ‎02-17-2010
My Carrier: Airtel

Re: Differentiating between Direct TCP & WAP 2.0 network connections

Thanks for replying...

 

Actually you didn't understood what I'm asking for, I've a third-party application (not written by me) and I want to know at a particular time which network option it is using by viewing Event Logs.

I can differentiate all transport options but i case of TCP and WAP2.0 it was showing similar logs. So I want to know is it possible by any means to determine whether an application used TCP or WAP2.0 network connection at runtime!!!

Please use plain text.
Developer
peter_strange
Posts: 17,952
Registered: ‎07-14-2008

Re: Differentiating between Direct TCP & WAP 2.0 network connections

How do you know that it it using Direct TCP and/or WAP?

 

As I asked in my original response, can you tell us what device and carrier are you looking on?  Are both options supported on it?

 

Can you paste in the log entries that you see?

Please use plain text.