#include "ttp.h"
#include "ttppdu.h"
#include "CBufferSegment.h"
#if (hasTracing > 0 && hasTTP2Tracing > 0)
enum IrTinyTP2TraceCodes
{
kHandleConnectIndication = 1,
kHandleConnectConfirm,
kHandleDisconnectIndication,
kHandleDataIndication,
kDataLessPacket
};
static
EventTraceCauseDesc gTraceEvents[] = {
{kHandleConnectIndication, "TinyTP2: connect indication"},
{kHandleConnectConfirm, "TinyTP2: connect confirm"},
{kHandleDisconnectIndication, "TinyTP2: disconnect indication"},
{kHandleDataIndication, "TinyTP2: data indication"},
{kDataLessPacket, "TinyTP2: dataless indication"}
};
#define XTRACE(x, y, z) IrDALogAdd( x, y, z, gTraceEvents, true )
#else
#define XTRACE(x, y, z) ((void)0)
#endif
void
TTinyTP::TTPHandleConnectIndication (
IrDAErr result,
TTPSAP sap, TIrQOS *ourQOS, TIrQOS *peerQOS, TTPBuf *userData) {
unsigned char plist[100]; int p; int n;
XTRACE(kHandleConnectIndication, 0, result);
if (result != noErr) {
TTPConnectIndication(result, sap, ourQOS, peerQOS, this->TxMaxSduSize, userData); return;
}
ttp_pdu_connect_parse(userData, &p, &n, &plist[0]); this->SendCredit = n;
this->TxMaxSduSize = 0;
this->MaxSegSize = peerQOS->GetDataSize() - 3;
if (p == 1) {
UInt32 value;
if (ttp_pdu_connect_get_max_sdu_size(plist, &value))
this->TxMaxSduSize = value;
}
TTPConnectIndication(result, sap, ourQOS, peerQOS, this->TxMaxSduSize, userData); }
void
TTinyTP::TTPHandleConnectConfirm (
TTPSAP sap, TIrQOS *ourQOS, TIrQOS *peerQOS, TTPBuf *userData) {
unsigned char plist[100]; int p; int n;
XTRACE(kHandleConnectConfirm, 0, 0);
ttp_pdu_connect_parse(userData, &p, &n, &plist[0]); this->SendCredit = n;
this->TxMaxSduSize = 0;
this->MaxSegSize = peerQOS->GetDataSize() - 3;
if (p == 1) {
UInt32 value;
if (ttp_pdu_connect_get_max_sdu_size(plist, &value))
this->TxMaxSduSize = value;
XTRACE(kHandleConnectConfirm, 1, value);
}
this->Connected = true;
{ CBufferSegment *getBuf;
getBuf = BufAlloc(2048+5); require(getBuf, NoMem); this->DataGet(getBuf); }
TTPConnectConfirm(sap, ourQOS, peerQOS, this->TxMaxSduSize, userData); BufFree(userData); NoMem:
return;
}
void
TTinyTP::TTPHandleDisconnectIndication (
int reason, TTPBuf *userData)
{
XTRACE(kHandleDisconnectIndication, 0, 0);
this->Connected = false;
this->FlushQueue(&(this->TxQueue));
txQDepth = 0;
this->AppendTail(&(this->RxQueue), TTP_Disconnect, reason, userData);
}
void
TTinyTP::TTPHandleDataIndication (
TTPBuf *userData) {
int credit;
Boolean m;
check(userData);
{ int position, bufsize;
position = BufUsed(userData); bufsize = BufSize(userData); XTRACE(kHandleDataIndication, position, bufsize);
}
ttp_pdu_data_parse(userData, &m, &credit); this->SendCredit += credit;
if (SendCredit > 30) SendCredit = 30;
if (credit > 0) TTPBackEnable();
if (BufSize(userData) > 0) {
XTRACE(kHandleDataIndication, m, credit); this->RemoteCredit--;
if (m == false) this->AppendTail(&(this->RxQueue), TTP_Segment_Last, 0, userData);
else this->AppendTail(&(this->RxQueue), TTP_Segment, 0, userData);
}
else {
XTRACE(kDataLessPacket, m, credit); BufFree(userData); }
if( this->Connected )
{ CBufferSegment *getBuf;
getBuf = BufAlloc(2048+5); require(getBuf, NoMem);
this->DataGet(getBuf);
}
NoMem:
return;
}
void
TTinyTP::TTPHandleUDataIndication (
TTPBuf *userData) {
TTPUDataIndication(userData);
}
void
TTinyTP::TTPHandleAcceptComplete(IrDAErr result, TTPBuf *userdata)
{
check(userdata);
BufFree(userdata); TTPAcceptDoneIndication(result); }