GPRS Connection Issues - Windows Mobile Development and Hacking General

Hi All,
My app is required to update certain information to my server every 15mins or so. This data is being successfully posted, however on reviewing my phone bill, the code is forcing a new GPRS connection with each post.
I use the ConnectionManager API to get a handle to the optimal/current connection:
Code:
DWORD dwCurrentStatus;
ConnMgrConnectionStatus(hConnection, &dwCurrentStatus);
if (dwCurrentStatus != CONNMGR_STATUS_CONNECTED){
ConnMgrEstablishConnectionSync(&sCI, &hConnection, 30000, &dwStatus);
}
// Make outgoing internet connection.
hInternetSession = InternetOpen(TEXT("My App"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
// Connect to the server
hServerSession = InternetConnect(hInternetSession, szServer, INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, NULL, NULL);
if(hInternetSession == NULL || hServerSession == NULL){
return false;
}
After each post I close the internet handle ( I am fairly sure this shouldn't drop the GPRS connection):
Code:
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
On application SHUTDOWN I allow the connection to close:
Code:
ConnMgrReleaseConnection(hConnection, 0);
if(hConnection){
hConnection = NULL;
}
InternetCloseHandle(hHttpSession);
InternetCloseHandle(hServerSession);
InternetCloseHandle(hInternetSession);
hHttpSession = NULL;
hServerSession = NULL;
hInternetSession = NULL;
Has anyone else had similar problems or is aware of what I am doing wrong?
Cheers

gprs connection
i have a small app that changes gprs connection when one of them is down, but i have found that the connmgrreleaseconnection call does not work, and the current connection will not die, you may have the same problem

Related

Passing string variable to dll -> NotSupportedException

This is all very frustrating! I have an "ez_tapi.dll" from Paul Vangelderp and it works a treat for eVB but I can not seem to use it in C#.
If anybody feel inspired they can test this themselves: the zipped attachment contains Paul's DLL code (C++ project) and his small test project (eVB), which proves that the DLL works well. Also included is my micky-mouse C# test project: I can dial up a modem and establish a GSM/V.110 connection, but when I try to send data by calling Ez_tapi_UTransmit() the application blows. I am assuming we have a problem passing the string between managed and unmanaged code.
I have buggered about with every imaginable combination of ref and out (the C# equivalent of ByVal and ByRef) for both Unicode and with byte/char arrays - all I ever get is the totally unhelpful "NotSupportedException". Is this a marshaling issue and if so how can I fix it?
Any help would be most welcome - I think Paul is planning on offering his DLL as a general purpose encapsulation of TAPI for application programmers who only need to quickly make a dial-up data connection for their PocketPC projects... once we have got it working!
Best regards,
Peter Beedell.
Re:
You can wrap library in this method:
//Function to Dial up a telephone number and get a Comm Handle
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_UDial")]
private static extern int TAPIUDial(string szPhoneNumber);
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Dial")]
private static extern int TAPIDial(string szPhoneNumber);
//Function to Return the Current Tapi Status
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Status")]
private static extern uint TAPIStatus();
// Function to Return the TAPI handle
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Handle")]
private static extern uint TapiHandle();
//Function to close line and release all handles
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Shutdown")]
private static extern bool TapiShutDown();
//Transmit a Unicode string
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_UTransmit")]
private static extern bool TapiUTransmit(string txData, uint size);
//Transmit a Transmit a char (Byte) string
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Transmit")]
private static extern bool TapiTransmit(string txData, uint size);
//Receive a Unicode string
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_UReceive")]
private static extern uint TapiUReceive(string rxData, uint size);
//Receive a Receive a char (byte) string
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Receive")]
private static extern uint TapiReceive(string rxData);
// Return how many characters are waiting in the buffer
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Rx_Count")]
private static extern uint TapiRxCount();
//Wait for a Unicode Text String with timeout value
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_UWait")]
private static extern bool TapiUWait(string What, uint length, uint Timeout);
//Wait for a char (byte) Text String with timeout value
[DllImport("ez_tapi.dll", EntryPoint = "Ez_tapi_Wait")]
private static extern bool TapiWait(string What, uint length, uint Timeout);
bye

C# SendMessage to Ignore/Answer calls

I am in need of some help.
I need to be able to utilize the Win32 SendMessage API (via C#) to Ignore/Answer phone calls on a whim. The current test bed is Windows Mobile 5.0, and from what I have been able to gather, the program that I should be sending the message to is cprog.exe. So the question is, should I be sending anything other than the WM_LBUTTONDOWN, WM_RBUTTONDOWN events in order to do so?
Code:
public class Message
{
public const int WM_LBUTTONDOWN = 0x0201;
public const int WM_RBUTTONDOWN = 0x0204;
}
[DllImport("coredll.dll", EntryPoint = "SendMessage", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
...
Win32.SendMessage(pc.Handle, Win32.Message.WM_RBUTTONDOWN, 0, 0);
Well if you just want an app that will auto send a txt to a phone call that you can't answer, it's in the forums, Mobile Secretary. And yes, I believe from what your doing cprog.exe is the phone application.

SMS to Email Address programatically?

I did a search in the forum, and didn't see if this is mentioned, so forgive me if this has been discussed.
I am trying to programatically send an SMS to a normal email address... and I know the phone can do it (AT&T Tilt, AT&T service), as I can do it manually. My first approach (as to not start monkeying around with the MAPI stuff) is to try the SMS API (sms.h and sms.lib). I am trying to use the SmsSendMessage function. My code works great for messages to other phones, but fails with the very informative return code of E_FAIL when sending to a "normal" email address.
Is there a trick or a setting that I am missing?
Here is a code sample of what I am trying to do:
Code:
BOOL CSMSSender::Send( wchar_t *message )
{
if( message == NULL )
{
return FALSE;
}
SMS_HANDLE smsHandle;
SMS_ADDRESS source;
SMS_ADDRESS dest;
TEXT_PROVIDER_SPECIFIC_DATA textData;
SMS_MESSAGE_ID messageId;
HRESULT result = S_OK;
BOOL retVal = TRUE;
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return FALSE;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, GetSmsAddr( ), SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) message,
_tcslen( message ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );
if( result != S_OK )
{
retVal = FALSE;
goto EXIT;
}
EXIT:
result = SmsClose( smsHandle );
if( result != S_OK )
{
retVal = FALSE;
}
return retVal;
}
You can probably guess that GetSmsAddr( ) returns a wchar_t * that is the address I am trying to send it to. When it is a phone number, works swimmingly, when it is a "normal" email address, it fails. This is, of course, a snippet of a much larger system, but the only SMS specific stuff, and the stuff that gives me the problems. So, if you wonder "why did he do it this way", probably stuff missing that would make it more clear.
If the answer is to go swimming in the mess that is MAPI, then so be it... but would like to know if there is an easier answer before I put on my trunks...
Take Care,
Wicked96SS
Found the solution... I feel dumb... It is actually pretty easy. The provider is the one that does the conversion from SMS to "normal" email. And you have to send the SMS to the email gateway. The SMS has to be specially formatted. Here is a non comprehensive list of the formats expected by certain vendors:
Format (Carrier;SMS to Email Gateway Number;Text Format)
AT&T (Formerly Cingular) USA;111 or 121;emailaddress (subject) text
CTI (Argentina);6425;emailaddress (subject) text
Swisscom Mobile AG (only Switzerland);555;<emailaddress> <subject>/<text>
T-Mobile Austria http://t-mobile.at;6761;<emailaddress> <text>
T-Mobile (USA);500;<emailaddress> / <subject> / <text>
Anyhow, still looking for Verizon and some others, but i am sure they are simple.
So, if configured like that, and sent to the correct number, I do get SMS messages to normal email accounts.
Code snippet for AT&T
Code:
result = SmsOpen( SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smsHandle, NULL );
if( result != S_OK )
{
return SMS_INIT_FAILED;
}
// Setup source address...
dest.smsatAddressType = SMSAT_UNKNOWN;
_tcsncpy( dest.ptsAddress, L"111", SMS_MAX_ADDRESS_LENGTH );
// Setup the provider information...
memset( &textData, 0, sizeof( textData ) );
textData.dwMessageOptions = PS_MESSAGE_OPTION_NONE; // No confirmation...
textData.psMessageClass = PS_MESSAGE_CLASS1;
textData.psReplaceOption = PSRO_NONE;
textData.dwHeaderDataSize = 0;
std::wstring body;
body = L"[email protected](Hi!)Here is the body";
result = SmsSendMessage( smsHandle,
NULL,
&dest,
NULL,
(PBYTE) body.c_str( ),
_tcslen( body.c_str( ) ) * sizeof (wchar_t),
(PBYTE) &textData,
sizeof( TEXT_PROVIDER_SPECIFIC_DATA ),
SMSDE_OPTIMAL,
SMS_OPTION_DELIVERY_NONE,
&messageId );
Question on Normal Emails
I found your posting and it works great for sending sms messages to cell phone emails.
I found this link that shows the other gateways you were looking for.
http://en.wikipedia.org/wiki/SMS_gateways
My question is did you ever get this to work to send emails to network email address like [email protected]
let me know if you have any suggestions.
Thanks in Advance
ColoradoGene
hello ColoradoGene! Sorry for the time it took to respond, but yes, I have been able to send SMS messages to email addresses... the message has to be formatted correctly. The source code in my post (#2) will work for AT&T.
What problems are you actually having?

PPC with Windows Mobile as Server

I have tried for some hours now to catch the problem, nowhere are good resources to read.
I have a server application running on my phone (Windows Mobile 6.1)
Binding the TCP Listener to 127.0.0.1ORT does work, if I type the URL from within the device.
Then I tried to connect via WIFI. At first: All WiFi Settings are correct, I know all IPs and pings are possible ... BUT: When I try to access the server from within the wifi network I don't get through. I've bound the listener for testing purposes to 127.0.0.1 and to the IP of my Wifi card. but nothing helped. Is there a kind of firewall or why can't I use a socket connection from PC to PPC?
This should work. I've create a remote-control program via TCP/IP and there were no issues.
Can you post the code for Bind / Listen?
radhoo said:
Can you post the code for Bind / Listen?
Click to expand...
Click to collapse
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Provided your code is good, maybe check if the socket is actually listening, there's netstat tool in dotFred's task manager: http://www.dotfred.net/TaskMgr.htm
Furthermore, you can see if the traffic ever reaches your PPC with hSniffer:
http://winm-soft.atspace.com/
You don't seem to be checking any of the return values.
Have you done that?
You might be facing different conditions than when you bind to the loopback adapter.
theq86 said:
Code:
byte[] byteBuffer = new byte[1024];
string stringBuffer = null;
[COLOR="Red"] IPAddress localhost = IPAddress.Parse("0.0.0.0");
// I also tried 127.0.0.1 and the IP of my phone in WiFi
TcpListener httpDaemon = new TcpListener(localhost, 80);
httpDaemon.Start();
[/COLOR]
while (true)
{
TcpClient httpBrowser = httpDaemon.AcceptTcpClient();
NetworkStream commStream = httpBrowser.GetStream();
int i;
// Loop to receive all the data sent by the client.
while ((i = commStream.Read(byteBuffer, 0, byteBuffer.Length)) != 0)
{
stringBuffer = System.Text.Encoding.ASCII.GetString(byteBuffer, 0, i);
}
MessageBox.Show(stringBuffer);
httpBrowser.Close();
Click to expand...
Click to collapse
try other different port rather than http port = 80
mobile phone not design to be a web server.

Samsung devices not sending IPv6 Multicast datagrams

Hey, sorry if this is in the wrong forum, but I was not exactly sure where to post this.
I'm facing problems sending UDP packets over IPv6 multicast addresses on Galaxy devices.
Particularly, I want to send a Wake-on-LAN Magic Packet over IPv6 to wake up a PC in a different network. That PC is only reachable from outside via IPv6. Since it doesn't have an IP address when it's turned off, I can't send the Magic Packet directly to the computer and need to broadcast it over the network. I'm pretty new to IPv6, so I had to do some research on how to broadcast packets over IPv6 first and I'm not quite sure, if I'm doing everything correctly.
So, let's suppose the network the PC is connected to has the following network prefix:
2a02:123:4567:89ab::/64
According to RFC3306, I can use that prefix to derive a global multicast address, which would be the following:
ff3e:40:2a02:123:4567:89ab:0:0
Packets sent to this address should reach all devices on the network.
I wrote a small method to send a UDP packet to that multicast IP address and checked with Wireshark, if the packets were received or not.
When I run the method in a regular Java application, everything works fine and the packet is received by all devices on the network. When I use the same method in an Android app, I notice a strange behavior. If I send the packet from Non-Samsung devices (e.g. Blackview BV2000s) there are no problems. But from Samsung devices (Galaxy S3, S6 and Note 4 to be precise), the packet is not received by the PC. I think, the devices don't even send out the packet. Strange enough, if I address the PC directly with it's unicast address (e.g. 2a02:123:4567:89ab:cdef:fedc:ba98:7654), the packet is sent and received without any problems. So the problem only occurs on Samsung devices and only when sending to multicast addresses.
I'm using the following method to send the packet:
Java:
public void sendMagicPacket(String host, int port, String macAddress) {
try {
InetAddress address = InetAddress.getByName(host);
String[] macData = macAddress.split("\\:");
byte[] mac = new byte[6];
for (int i = 0; i < 6; i++) {
mac[i] = (byte)Short.parseShort(macData[i], 16);
}
byte[] magic = new byte [102];
for (int i = 0; i < 6; i++) {
magic[i] = (byte)0xff;
}
for (int i = 6; i < 102; i++) {
magic[i] = mac[i%6];
}
DatagramPacket packet = new DatagramPacket(magic, magic.length, address, port);
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
socket.close();
} catch (final Exception e) {}
}
I'm pretty sure there is nothing wrong with the method itself, but am I missing something Android specific? Is sending to IPv6 multicast addresses not supported by Samsung devices or is it a bug? I'm pretty helpless and have no idea how to solve this problem. I hope someone can help me with this. :fingers-crossed:

Categories

Resources