2018-03-12 11:22:06 +01:00
|
|
|
#include "conn.h"
|
|
|
|
#include "cw.h"
|
|
|
|
#include "dbg.h"
|
|
|
|
|
2018-03-17 17:29:09 +01:00
|
|
|
#define CW_MODE_ZYXEL 7
|
2020-04-03 00:45:53 +02:00
|
|
|
extern cw_send_msg(struct conn * conn,uint8_t * msg);
|
2018-03-17 17:29:09 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
int conn_send_msg(struct conn * conn, uint8_t *rawmsg)
|
|
|
|
{
|
|
|
|
uint8_t * ptr;
|
|
|
|
int packetlen;
|
|
|
|
int fragoffset,hlen,mtu;
|
|
|
|
|
|
|
|
packetlen = cw_get_hdr_msg_total_len(rawmsg);
|
|
|
|
|
|
|
|
cw_dbg_msg(DBG_MSG_OUT, conn,rawmsg, packetlen,(struct sockaddr*)&conn->addr);
|
|
|
|
|
2020-04-03 00:45:53 +02:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
/* Zyxel doesn't count msg element length from
|
|
|
|
behind seqnum */
|
|
|
|
if (conn->capwap_mode == CW_MODE_ZYXEL){
|
|
|
|
/* // XXX val-=3; */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ptr = rawmsg;
|
|
|
|
|
|
|
|
fragoffset = 0;
|
|
|
|
|
|
|
|
hlen = cw_get_hdr_hlen(rawmsg)*4;
|
|
|
|
|
|
|
|
mtu = conn->mtu;
|
2022-07-28 01:36:16 +02:00
|
|
|
mtu = 9440;
|
2020-04-03 00:45:53 +02:00
|
|
|
mtu = mtu >> 3;
|
|
|
|
mtu = mtu << 3;
|
|
|
|
|
|
|
|
printf("packetlenX = %d (%d)\n",packetlen,hlen);
|
|
|
|
int offset = cw_get_hdr_msg_offset(rawmsg);
|
|
|
|
return cw_send_msg(conn,rawmsg+offset);
|
|
|
|
|
|
|
|
|
|
|
|
if (packetlen>mtu){
|
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_F,1);
|
|
|
|
cw_set_dword(ptr+4, conn->fragid<<16 | fragoffset<<3 );
|
|
|
|
cw_dbg_pkt(DBG_PKT_OUT,conn,ptr,mtu,(struct sockaddr*)&conn->addr);
|
|
|
|
if (conn->write(conn,ptr,mtu)<0)
|
|
|
|
return -1;
|
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_M,0);
|
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_W,0);
|
|
|
|
|
|
|
|
fragoffset+=(mtu-hlen)/8;
|
|
|
|
hlen = 8;
|
|
|
|
ptr += mtu-hlen;
|
|
|
|
packetlen-=mtu-hlen;
|
|
|
|
memcpy(ptr,rawmsg,hlen);
|
|
|
|
|
|
|
|
}
|
2018-05-07 10:56:56 +02:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
while (packetlen>mtu){
|
2018-05-07 10:56:56 +02:00
|
|
|
|
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_F,1);
|
2018-03-25 10:35:53 +02:00
|
|
|
cw_set_dword(ptr+4, conn->fragid<<16 | fragoffset<<3 );
|
2018-03-12 11:22:06 +01:00
|
|
|
|
|
|
|
cw_dbg_pkt(DBG_PKT_OUT,conn,ptr,mtu,(struct sockaddr*)&conn->addr);
|
|
|
|
|
|
|
|
if (conn->write(conn,ptr,mtu)<0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* // XXX Fragmentation stuff.. */
|
|
|
|
ptr +=mtu-hlen;
|
|
|
|
fragoffset+=(mtu-hlen)/8;
|
|
|
|
|
|
|
|
packetlen-=mtu-hlen;
|
2018-05-07 10:56:56 +02:00
|
|
|
memcpy(ptr,rawmsg,hlen);
|
2018-03-12 11:22:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (fragoffset)
|
2018-05-07 10:56:56 +02:00
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_F | CAPWAP_FLAG_HDR_L,1);
|
2018-03-12 11:22:06 +01:00
|
|
|
else
|
2018-05-07 10:56:56 +02:00
|
|
|
cw_set_hdr_flags(ptr,CAPWAP_FLAG_HDR_F,0);
|
2018-03-12 11:22:06 +01:00
|
|
|
|
2018-03-25 10:35:53 +02:00
|
|
|
cw_set_dword(ptr+4, conn->fragid<<16 | fragoffset<<3 );
|
2018-03-12 11:22:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
cw_dbg_pkt(DBG_PKT_OUT,conn,ptr,packetlen,(struct sockaddr*)&conn->addr);
|
|
|
|
|
|
|
|
return conn->write(conn,ptr,packetlen-0);
|
|
|
|
}
|
|
|
|
|