Sorry for being unclear. I am working on a WAP browser that uses the
Wireless Application Protocol, Segmentation and Reassembly to be specific.

I have gone through and "cleaned" the code up a little bit (so it is more
consistant).

For starters here is a basic WTP SAR session: (just the server reply)

                                  \/ WTP Header, what tells me the packet
order, if the packet is last, when to ack...
1. server to client: 10 c8 49 (a lot of octets, the segmented data I am
going to reassemble)
2. server to client: 32 c8 49 01 (the rest of the data)

3. client to server: 98 48 49 19 01 (WAPUniverse can successfully send this)

I want the "data" (what would be in parenthesis) temporarily put in SARbuf,
then move back into buf.

I have not been able to get WAPUniverse (the WAP browser) to reply to more
complex SAR "sessions", although it does reply fine to the one stated above.
The following "snipet" of a WAP session, WAPUniverse fails to reply
 WTPAck, and varients).

                                  \/ WTP Header, what tells me the packet
order, if the packet is last, when to ack...
1. server to client: 10 c8 54 (bunch of wanted data)
2. server to client: 30 c8 54 01 (more wanted data)
3. server to client: 34 c8 54 02 (more data)
4. client to server: 98 48 54 99 02 13 04 14 00 (the is where WAPUniverse
fails to reply back)
5. server to client: 32 c8 54 03 (last chunk of data) (this would be sent if
WAPUniverse reply above)
6. client to server: 98 48 54 19 03 (ack WAPUniverse would send if it got
here)

The 4th byte on packets 2,3 and 5 denote the packet position once
reassembled. On all the server to client packets the second and third bytes
are the transaction ID and the first byte is the PDU and some flags (i.e. is
the packet last in group, last in message, not last, etc. etc.).

My guess is that WAPUniverse does not respond to the second example because
it receives two packets, although it does this in the forst example too and
WAPUniverse handles it just fine, except for the buffers.

Thanks again,
Donald

---Slightly updated code---

Int16 WspGetReply(Int16 sock, char *buf, Int16 buflen, UInt32
maxTimer,GlobalsType *g)
{
    Int16     ret;
    unsigned char rep[500];
    int j = 0;
    UInt32 waitTimer;
    char *SARbuf;
    int s = 0, t = 0;

    SARbuf = NULL;

    AppNetTimeout = 4 * SysTicksPerSecond();

    // please don't turn me off now
    EvtResetAutoOffTimer();


for(;;) {

start:

    ret = recv(sock,buf,buflen,0);

    if ((errno==netErrTimeout) && ( TimGetTicks() < maxTimer ) ) {
        return(0);
    }

    if (ret <= 0) {
     g->progress= 0;
     showProgress2(g);
        g->state = BS_IDLE;
 SetFieldFromStr2("WAPUniverse",fieldTitle);
        if (ret == 0) {
         MyErrorFunc2("Could not receive data from server. Connection closed
by remote host.","Receive");
   return(-1);//ret = -1;
   break;
        }
        MyErrorFunc2("\nCould not receive data from the
server.\nReason:\n",WspHostErrStr());
 if (g->conn.connectionType == 'O') {
  WTPAbort (sock, g);
 }
        if (errno == ENOMEM) {
         MyErrorFunc2("ENOMEM","");
        }
 ret = -10;
 break;
    } else {
 if (g->conn.connectionType == 'O') {
  /*if (buf[0] == 0x12) {
   WTPAck(sock, g);
   break;
  }
  file://Hande Segmentation and Reassembly
  else if ((((buf[0] & 0x78) >> 3) == 0x06) || (((buf[0] & 0x78) >> 3) ==
0x02)) {
   s += ret;
   if ((!SARbuf) || (SARbuf == NULL)) {
    SARbuf = Malloc(ret+1);
    ErrFatalDisplayIf(!SARbuf, "Malloc failed");
   }

   if (((buf[0] & 0x78) >> 3) == 0x02) { // Result
    memcpy(SARbuf, buf+3, ret-3);
    goto start;
   } else if (((buf[0] & 0x78) >> 3) == 0x06) { // Segmented Result
    t ++;
    MemPtrResize (SARbuf, s);
    memcpy(SARbuf+(s-ret-4), buf+4, ret-4);
   }

   if (((buf[0] & 0x07) >> 1) == 0x02) { file://Last packet of group
    SARGrpWTPAck(sock, t, g);
    goto start;
   } else if (((buf[0] & 0x07) >> 1) == 0x01) { // End of transmission
    SARWTPAck(sock, t, g);

    // Copy SARbuf into buf
    MemPtrResize(buf, MemPtrSize(SARbuf));
    memcpy(buf, SARbuf, MemPtrSize(SARbuf));
    Free(SARbuf);
    break;
   } else { // Not Last

    goto start;
   }
  }
  file://Some gateways are too concerned and send Ack after just about
anything we send, so
  file://we must learn to ignore unwanted Ack's
  else if (buf[0] == WTP_Ack1) {
   ret = WspGetReply(sock,buf,buflen,maxTimer,g);
   return(ret);
   break;
  } else if ((buf[0] == WTP_Abort1) || (buf[0] == WTP_User_Abort)) {
   MyErrorFunc2("Could not receive data from server. Remote host sent
Abort.","Receive");
   return(-20);
   break;
  }
  else { file://acknowledge that we got it
   WTPAck(sock, g);
      }*/

  switch ((buf[0] & 0x78) >> 3) {
   case WTP_Result:
    switch ((buf[0] & 0x07) >> 1)

     case 0x03:// SAR Not supported
     case 0x01:// End of transmission
      WTPAck(sock, g);
      break;
     case 0x00:// Not Last
      if ((!SARbuf) || (SARbuf == NULL)) {
       SARbuf = Malloc(ret+1);
       ErrFatalDisplayIf(!SARbuf, "Malloc failed");
      }
      s += ret;
      memcpy(SARbuf, buf+3, ret-3);
      goto start;
      break;
    }
    break;
   case WTP_SAR_Result:
    if ((!SARbuf) || (SARbuf == NULL)) {
     SARbuf = Malloc(ret+1);
     ErrFatalDisplayIf(!SARbuf, "Malloc failed");
    }
    s += ret;
    t++;
    MemPtrResize (SARbuf, s);
    memcpy(SARbuf+(s-ret-4), buf+4, ret-4);

    switch ((buf[0] & 0x07) >> 1)

     case 0x02: file://Last packet of group
      SARGrpWTPAck(sock, t, g);
      goto start;
      break;
     case 0x01: // End of transmission
      SARWTPAck(sock, t, g);

      // Copy SARbuf into buf
      MemPtrResize(buf, MemPtrSize(SARbuf));
      memcpy(buf, SARbuf, MemPtrSize(SARbuf));
      Free(SARbuf);
      break;
     case 0x00: // Not Last
      goto start;
      break;
    }
    break;
   case WTP_Ack:
   file://Some gateways are too concerned and send Ack after just about
anything we send, so
   file://we must learn to ignore unwanted Ack's
    ret = WspGetReply(sock,buf,buflen,maxTimer,g);
    return(ret);
    break;
   case WTP_Abort:
    MyErrorFunc2("Could not receive data from server. Remote host sent
Abort.","Receive");
    return(-20);
    break;
   default:
    WTPAck(sock, g);
        break;
  }
  break;
     }


    }

break;
}

    return(ret);
}



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to