data transmitting in GSM - Windows Mobile Development and Hacking General

Hello.
I've to solve next project:
I have Pocket PC with GSM-module and measuring instrument, which is connected to the Pocket PC. This instrument is measuring in real-time and software is questioning this instrument. Then the software have to make packets and send it via GSM to the another server. On the server side there is same GSM-module. Packet is near 5-14 bytes. For calling program is using TAPI.
Now about the problems I've to solve:
1. When I sending a small data packet ( for example 14 bytes) another side don't receiving anything. The data is receivibg only when the packet size is near 200 bytes. How can I solve it?
2. When the equipment or server is working in arear with bad GSM-coverage, the program doesn’t receive signal of overflow from the modem and sending data anyway. Then when the coverage is going better the data is lagging because the buffer has many packets of data and begins send it. How can I control that buffer? When the packets are not sending right away they have to ignore but they are exist anyway.
3. Where I can to read about data transmitting in GSM ( for beginners)?

There is nothing special about the size, I have been sending from 5 bytes to 12000 bytes in various programs and it makes no difference. Are you using WaitCommEvent with EV_RXCHAR? before doing the read.

I use presented below a code:
for read data from port:
Code:
...
::ClearCommError( m_hPort, &nStatus, &sCommStat );
if( sCommStat.cbInQue == 0 )
{
::WaitCommEvent( m_hPort, &m_dwEvent, NULL );
::SetCommMask( m_hPort, EV_RXCHAR );
::ReadFile( m_hPort, pData, sizeLen, &dwRead, 0 );
}
else
{
::ReadFile( m_hPort, pData, sizeLen, &dwRead, 0 );
}
...
for sending data to port:
Code:
...
::WriteFile( m_hPort, pData, sizeLen, &dwWritten, 0 );
::FlushFileBuffers( m_hPort );
...
What correct parameters should be at functions:
SetupReadTimeouts
SetupComm
SetCommState

Related

Wininet HttpSendRequest over GPRS

Hi
I wondered if anyone has any tips on using Wininet over GPRS. I'm currenct using eVc 4 to write an application that sends data to a web server using the Wininet HttpSendRequest or HttpSendRequestEx Functions. The problem I get is when I try to send more than about 10k of data I get a server timeout using the GPRS connection but everything seems fine when I have the XDAii in the cradle.
Ok so the problem seems to be GPRS being slow and unreliable but I have experimented with sending the data in 1k chunks and the problem comes when trying to end the http request with HttpEndRequest. I have checked the server timeouts on my IIS server and they are all set to 15 minutes.
Does anyone have any clues?
This is the code I use to do a similar thing with a photo which works quite well
Are you setting the response to nothing?
GPRS is very unreliable but I have managed to send 70k files over it.
==========
Private Function FileUpload(ByVal sURL As String, ByVal sFile As String) As String
On Error GoTo eh
Dim binReader As BinaryReader
Dim byteArray() As Byte
binReader = New BinaryReader(File.OpenRead(sFile))
byteArray = binReader.ReadBytes(binReader.BaseStream.Length)
Dim httpURI As New Uri(sURL & sFile)
Dim httpRequest As HttpWebRequest = httpRequest.Create(httpURI)
httpRequest.Method = "POST"
httpRequest.ContentLength = binReader.BaseStream.Length
Dim httpReqStream As Stream
httpReqStream = httpRequest.GetRequestStream
httpReqStream.Write(byteArray, 0, byteArray.Length)
httpReqStream.Close()
Dim httpResponse As HttpWebResponse
httpResponse = httpRequest.GetResponse
Dim sResponse As String
sResponse = CStr(httpResponse.StatusDescription)
FileUpload = "OK"
httpResponse.Close()
binReader.Close()
httpURI = Nothing
httpRequest = Nothing
httpReqStream = Nothing
binReader = Nothing
httpResponse = Nothing
byteArray = Nothing
Exit Function
eh:
MsgBox(Err.Description)
binReader.Close()
FileUpload = "ERROR"
httpURI = Nothing
httpRequest = Nothing
httpReqStream = Nothing
binReader = Nothing
httpResponse = Nothing
End Function
===================
My code seems to be fine as when I used my mates Vodafone sim in the Xda ii I was able to send a 40k file straight away. It seems there is a limit somewhere around the 8-9k mark in the O2 gprs apn. I have to now get on to 02 and find out how they will let me send more than 8k at a time.
There is a problem with O2. They had to give me a new username and password to log onto their network, which has different privileges, to get around it.
Good Luck

Send a file from server to client via stream

hi,
I currently have a client server app which passes back and forth String data and it works great. but now i have the need to send non text files ie images from server to client (PPC). It is all based on system.net.sockets.
The client is making a request via the following
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(lData)
lnetworkStream.Write(sendBytes, 0, sendBytes.Length)
Dim bytes(ltcpClient.ReceiveBufferSize) As Byte
lnetworkStream.Read(bytes, 0, CInt(ltcpClient.ReceiveBufferSize))
Dim returndata As String = Encoding.ASCII.GetString(bytes, 0, bytes.Length)
The server code is responding via the following .
Private Sub sendmessage(ByVal s As Socket, ByVal message As String)
Buffer = New [Byte](message.Length + 1) {}
Dim length As Integer = ASCII.GetBytes(message, 0, message.Length, Buffer, 0)
s.Send(Buffer, length, 0)
End Sub 'sendmessag
Can any one one help, i can't seem to find any help on sending and receiving files via sockets.
thanks in advance

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?

(Solution) Enabling Exchange 2003 to receive HTML

PURPOSE
So the purpose of this thread is to explain how I got HTML working for Exchange 2003 servers which technically is not supposed to be possible This is me giving back to the community and I give full writes to use this code in whatever means necessary. I had to figure this out on my own with absolutely no help online so now I'm putting this here so no one else has to go through the hell that I did!
This means Hotmail via Activesync will also have full HTML support with this code patch I'm submitting.
First, AOSP Email is set up to request plain text emails from an Exchange 2003 server which is no good for us. First step is we need to request MIME messages which will contain the text/plain & text/html versions of an e-mail. So if a message was originally text/html then the MIME message will contain text/plain & text/html. If the original message was text/plain then the MIME message will only contain text/plain. No biggie there that's obviously ok.
EasSyncService.java
Code:
// Set the truncation amount for all classes
if (mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) {
s.start(Tags.BASE_BODY_PREFERENCE)
// HTML for email; plain text for everything else
.data(Tags.BASE_TYPE, (className.equals("Email") ?
Eas.BODY_PREFERENCE_HTML : Eas.BODY_PREFERENCE_TEXT))
.data(Tags.BASE_TRUNCATION_SIZE,
Eas.EAS12_TRUNCATION_SIZE)
.end();
} else {
if (className.equals("Email")) {
s.data(Tags.SYNC_MIME_SUPPORT, "2")
.data(Tags.SYNC_MIME_TRUNCATION, "7");
}
s.data(Tags.SYNC_TRUNCATION, Eas.EAS2_5_TRUNCATION_SIZE);
}
Explanation
The section in the if() block is for exchange 2007/2010 and basically is telling the Exchange server to send HTML for Email and plain text for anything else (ie: calendar events).
This says send me MIME messages for Exchange 2003
Code:
s.data(Tags.SYNC_MIME_SUPPORT, "2")
This says truncate the MIME message to 102,400 characters and is very important. If you don't set this then you WILL run into out of memory issues because some messages can be very large and since a MIME message contains duplicate copies of a message in two formats you're doubling the memory requirements.
Code:
.data(Tags.SYNC_MIME_TRUNCATION, "7");
Now let's get on to the part that will actually parse the MIME encoded message.
EmailSyncAdapter.java
Code:
public void addData (Message msg) throws IOException {
ArrayList<Attachment> atts = new ArrayList<Attachment>();
mimeAtts = new ArrayList<String>();
textBody = new StringBuffer();
htmlBody = new StringBuffer();
The new additions are mimeAtts, textBody, and htmlBody. We'll use these later in the code.
Code:
case Tags.EMAIL_MIME_DATA:
try {
MimeMessage mimeMsg = new MimeMessage(new ByteArrayInputStream(getValue().getBytes()));
if (mimeMsg.getBody() instanceof Multipart) {
MimeMultipart multipart = (MimeMultipart) mimeMsg.getBody();
parseMimeBody(multipart);
if (htmlBody != null && htmlBody.length() != 0)
msg.mHtml = htmlBody.toString();
else if (textBody != null)
msg.mText = textBody.toString();
else
msg.mText = "";
}
else {
InputStream in = mimeMsg.getBody().getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
in.close();
in = null;
String charset = MimeUtility.getHeaderParameter(mimeMsg.getContentType(), "charset");
if (charset == null)
charset = "UTF-8";
String mimeTxt = out.toString(charset);
charset = null;
out = null;
if (mimeMsg.isMimeType("text/html"))
msg.mHtml = mimeTxt;
else
msg.mText = mimeTxt;
}
} catch (MessagingException e) {}
break;
This is a new case block that I added specifically for parsing MIME encoded messages. In a nutshell I'm creating the MimeMessage object, checking if it is a multi-part message or single-part message and parsing accordingly.
Code:
if (atts.size() > 0 && mimeAtts != null) {
for(Attachment att : atts) {
for (String contentId : mimeAtts) {
if (contentId == null)
continue;
if (att.mFileName != null && contentId.contains(att.mFileName))
att.mContentId = contentId;
}
}
msg.mAttachments = atts;
}
This is really important and is still in the same method as the above two code sections. The issue is when an attachment is downloaded the content-id isn't specified. So now that we have the MIME message we can actually grab that content-id out of there and update each attachment with the correct content-id. Later in MessageView.java it will use that value to display the embedded images correctly.
Code:
private void parseMimeBody(MimeMultipart multipart) {
try {
for (int i=0; i<multipart.getCount(); ++i) {
BodyPart part = multipart.getBodyPart(i);
if (part.isMimeType("text/plain"))
textBody.append(MimeUtility.getTextFromPart(part));
else if (part.isMimeType("text/html"))
htmlBody.append(MimeUtility.getTextFromPart(part));
else if (part.isMimeType("multipart/alternative"))
parseMimeBody((MimeMultipart)part.getBody());
else
mimeAtts.add(part.getContentId());
}
}
catch (MessagingException e) {}
}
This is a new method I added which handles parsing out the message bodies from a multi-part MIME message. It uses recursion if there are embedded multi-part messages in the original multi-part message.
The last part which I won't paste here is incorporating the support for viewing MIME messages into MessageView.java. I've taken the 3 files that were modified and I'm attaching them to this e-mail. These are straight from my paid email app so there are other additions in there that someone can diff out. If I get time I'll patch these changes into AOSP email but I'm swamped 24/7 with Enhanced Email so I'd suggest someone else do it and contact me with questions.
This is the same hack that iPhone uses to enable HTML for ex2003 and once again is undocumented ANYWHERE on the net except for here by me
So... with this zip file (I don't know much about unpacking it in android- I am a winmo 6.5 user). I will be able to use hotmail via exchange server and view attachments ...etc just like an regular email client would behave?
I want to migrate to Android so bad, but I don't want to give up my hotmail account. As of now this is how I am setup on winmo 6.5:
1. PH#s (contacts with PH#s) + Calendar - Gmail synced via microsoft exchange
2. Email (Hotmail) + Email contacts - synced via windows live email client
Any advise will be greatly appreciated. Also... I would like to combine somehow all my contacts in one directory that will be synced somehow between gmail (for google voice texts and calls) and hotmail (since I use this all over my PC's and add contacts from different locations. Thank you!!!

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