Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions
FaxPcap Class Reference
Inheritance diagram for FaxPcap:
Inheritance graph
[legend]
Collaboration diagram for FaxPcap:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self, outfile)
 
 add (self, ifp)
 

Data Fields

 date
 
 outfile
 
 prev_data
 
 seqno
 
 udpseqno
 

Static Public Attributes

 PCAP_PREAMBLE
 

Protected Member Functions

 _add_garbage (self, date)
 
 _add_preamble (self)
 
 _make_packet (self, ifp_data, is_ifp=True)
 

Detailed Description

Definition at line 56 of file spandspflow2pcap.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  outfile 
)

Definition at line 62 of file spandspflow2pcap.py.

62 def __init__(self, outfile):
63 self.outfile = outfile
64 self.date = None
65 self.seqno = None
66 self.udpseqno = 128
67 self.prev_data = None
68
69 # Only do this if at pos 0?
70

Member Function Documentation

◆ _add_garbage()

_add_garbage (   self,
  date 
)
protected

Definition at line 122 of file spandspflow2pcap.py.

122 def _add_garbage(self, date):
123 if self.date is None or date > self.date:
124 self.date = date
125
126 self.seqno = 0xffff
127 self.outfile.write(self._make_packet(
128 bytearray(b'GARBAGE'), is_ifp=False))
129

References FaxPcap._make_packet(), FaxPcap.date, logmsg.date, FaxPcap.outfile, FaxPcap.seqno, ast_bridge_hook_timer_parms.seqno, ast_frame.seqno, rtp_transport_wide_cc_packet_statistics.seqno, ast_rtp.seqno, and multicast_rtp.seqno.

Referenced by FaxPcap.add().

◆ _add_preamble()

_add_preamble (   self)
protected

Definition at line 119 of file spandspflow2pcap.py.

119 def _add_preamble(self):
120 self.outfile.write(self.PCAP_PREAMBLE)
121

References FaxPcap.outfile, and FaxPcap.PCAP_PREAMBLE.

Referenced by FaxPcap.add().

◆ _make_packet()

_make_packet (   self,
  ifp_data,
  is_ifp = True 
)
protected

Definition at line 130 of file spandspflow2pcap.py.

130 def _make_packet(self, ifp_data, is_ifp=True):
131 sum16 = bytearray(b'\x43\x21') # the OS fixes the checksums for us
132
133 data = bytearray()
134 if is_ifp:
135 data.append(len(ifp_data)) # length
136 data.extend(ifp_data) # data
137 self.prev_data, prev_data = data[:], self.prev_data
138 else:
139 data.extend(ifp_data)
140 prev_data = None
141
142 if prev_data:
143 if LOSSY and (self.seqno % 3) == 2:
144 self.udpseqno += 1
145 raise SkipPacket()
146
147 if EMPTY_RECOVERY:
148 # struct ast_frame f[16], we have room for a few
149 # packets.
150 packets = 14
151 data.extend([0, packets + 1] + [0] * packets)
152 data.extend(prev_data)
153 else:
154 # Add 1 previous packet, without the seqno.
155 data.extend([0, 1])
156 data.extend(prev_data)
157
158 # Wrap it in UDP
159 udp = bytearray(
160 b'\x00\x01\x00\x02%(len)s%(sum16)s%(seqno)s%(data)s' % {
161 b'len': pack('>H', len(data) + 10),
162 b'sum16': sum16,
163 b'seqno': pack('>H', self.seqno),
164 b'data': data})
165
166 # Wrap it in IP
167 ip = bytearray(
168 b'\x45\xb8%(len)s%(udpseqno)s\x00\x00\xf9\x11%(sum16)s'
169 b'\x01\x01\x01\x01\x02\x02\x02\x02%(udp)s' % {
170 b'len': pack('>H', len(udp) + 20),
171 b'udpseqno': pack('>H', self.udpseqno),
172 b'sum16': sum16,
173 b'udp': udp})
174
175 # Wrap it in Ethernet
176 ethernet = bytearray(
177 b'\x00\x00\x00\x01\x00\x06\x00\x30\x48\xb1\x1c\x34\x00\x00'
178 b'\x08\x00%(ip)s' % {b'ip': ip})
179
180 # Wrap it in a pcap packet
181 packet = bytearray(b'%(prelude)s%(ethernet)s' % {
182 b'prelude': pack(
183 '<IIII', int(mktime(self.date.timetuple())),
184 self.date.microsecond, len(ethernet), len(ethernet)),
185 b'ethernet': ethernet})
186
187 # Increase values.
188 self.udpseqno += 1
189
190 return packet
191
192
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)

References FaxPcap.date, logmsg.date, len(), FaxPcap.prev_data, FaxPcap.seqno, ast_bridge_hook_timer_parms.seqno, ast_frame.seqno, rtp_transport_wide_cc_packet_statistics.seqno, ast_rtp.seqno, multicast_rtp.seqno, and FaxPcap.udpseqno.

Referenced by FaxPcap._add_garbage(), and FaxPcap.add().

◆ add()

add (   self,
  ifp 
)
Add the IFP packet.

T.38 basic format of UDPTL payload section with redundancy:

UDPTL_SEQNO
- 2 sequence number (big endian)
UDPTL_PRIMARY_PAYLOAD (T30?)
- 1 subpacket length (excluding this byte)
- 1 type of message (e.g. 0xd0 for data(?))
- 1 items in data field (e.g. 0x01)
- 2 length of data (big endian)
- N data
RECOVERY (optional)
- 2 count of previous seqno packets (big endian)
- N UDPTL_PRIMARY_PAYLOAD of (seqno-1)
- N UDPTL_PRIMARY_PAYLOAD of (seqno-2)
- ...

Definition at line 71 of file spandspflow2pcap.py.

71 def add(self, ifp):
72 """
73 Add the IFP packet.
74
75 T.38 basic format of UDPTL payload section with redundancy:
76
77 UDPTL_SEQNO
78 - 2 sequence number (big endian)
79 UDPTL_PRIMARY_PAYLOAD (T30?)
80 - 1 subpacket length (excluding this byte)
81 - 1 type of message (e.g. 0xd0 for data(?))
82 - 1 items in data field (e.g. 0x01)
83 - 2 length of data (big endian)
84 - N data
85 RECOVERY (optional)
86 - 2 count of previous seqno packets (big endian)
87 - N UDPTL_PRIMARY_PAYLOAD of (seqno-1)
88 - N UDPTL_PRIMARY_PAYLOAD of (seqno-2)
89 - ...
90 """
91 # First packet?
92 if self.seqno is None:
93 # Add preamble.
94 self._add_preamble()
95 # Start a second late (optional).
96 self._add_garbage(ifp.date)
97
98 # Set sequence, and fill with missing leading zeroes.
99 self.seqno = 0
100 for i in range(ifp.seqno):
101 self.add(IFP(date=ifp.date, seqno=i, data=bytearray([0])))
102
103 # Auto-increasing dates
104 if self.date is None or ifp.date > self.date:
105 self.date = ifp.date
106 elif ifp.date < self.date.replace(microsecond=0):
107 assert False, 'More packets than expected in 1s? {!r}/{!r}'.format(
108 ifp.date, self.date)
109 else:
110 self.date += timedelta(microseconds=9000)
111
112 # Add packet.
113 self.seqno = ifp.seqno
114 try:
115 self.outfile.write(self._make_packet(ifp.data))
116 except SkipPacket:
117 pass
118
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)

References FaxPcap._add_garbage(), FaxPcap._add_preamble(), FaxPcap._make_packet(), FaxPcap.add(), FaxPcap.date, logmsg.date, spandspflow2pcap.IFP, FaxPcap.outfile, replace(), FaxPcap.seqno, ast_bridge_hook_timer_parms.seqno, ast_frame.seqno, rtp_transport_wide_cc_packet_statistics.seqno, ast_rtp.seqno, and multicast_rtp.seqno.

Referenced by FaxPcap.add().

Field Documentation

◆ date

date

Definition at line 64 of file spandspflow2pcap.py.

Referenced by FaxPcap._add_garbage(), FaxPcap._make_packet(), and FaxPcap.add().

◆ outfile

outfile

Definition at line 63 of file spandspflow2pcap.py.

Referenced by FaxPcap._add_garbage(), FaxPcap._add_preamble(), and FaxPcap.add().

◆ PCAP_PREAMBLE

PCAP_PREAMBLE
static
Initial value:
= n2b(
'd4 c3 b2 a1 02 00 04 00'
'00 00 00 00 00 00 00 00'
'ff ff 00 00 71 00 00 00')

Definition at line 57 of file spandspflow2pcap.py.

Referenced by FaxPcap._add_preamble().

◆ prev_data

prev_data

Definition at line 67 of file spandspflow2pcap.py.

Referenced by FaxPcap._make_packet().

◆ seqno

seqno

Definition at line 65 of file spandspflow2pcap.py.

Referenced by FaxPcap._add_garbage(), FaxPcap._make_packet(), and FaxPcap.add().

◆ udpseqno

udpseqno

Definition at line 66 of file spandspflow2pcap.py.

Referenced by FaxPcap._make_packet().


The documentation for this class was generated from the following file: