<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[LAN Module: Reading RAW-packets]]></title><description><![CDATA[<p dir="auto">Hello everyone!</p>
<p dir="auto">I would like to use an M5Stack (ESP32) with LAN module (w5500)<br />
to read CDP (Cisco Discovery Protocol) packages.</p>
<p dir="auto">Working examples of M5Stack (ESP32) with LAN module (w5500)  all using Layer3 and 4 (IP+TCP or IP+UDP).</p>
<p dir="auto">However, CDP works on Layer2 like pure ARP broadcasts.<br />
To do this, you probably have to open a socket in MAC RAW Mode.</p>
<p dir="auto">Examples that use the W5x00 in this mode can only be found on<br />
Atmega base. In addition, there is a huge mess of Ethernet libraries for<br />
Arduino. Incompatibilities with certain Arduino IDE versions.<br />
Libraries that don't know all the commands I use in the Atmega examples. Etc...</p>
<p dir="auto">The first goal for me now would be to receive all packets as raw data,<br />
or packets sent to the Ethernet multicast address (01-00-0C-CC-CC-CC).</p>
<p dir="auto">Can someone help me, with an excample Code that works on m5?<br />
Regards,<br />
Torsten</p>
]]></description><link>https://community.m5stack.com/topic/2115/lan-module-reading-raw-packets</link><generator>RSS for Node</generator><lastBuildDate>Fri, 13 Mar 2026 20:09:04 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2115.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 Jul 2020 19:17:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to LAN Module: Reading RAW-packets on Fri, 01 Jan 2021 12:40:32 GMT]]></title><description><![CDATA[<p dir="auto">This code is tested and work fine.  1 jan 2021</p>
<p dir="auto">/*  ==================================================================================================</p>
<hr />
<ul>
<li>projet SWID_M5 ( Switch ID pour M5Stack)</li>
</ul>
<hr />
<pre><code>      version 0.3
</code></pre>
<p dir="auto">date debut :  1 aout 2020</p>
<p dir="auto">MODIF      :  2 aout    2020</p>
<p dir="auto">modif      :  16-18 dec 2020   modif ethernet2 serveur  tester et fonctionnel</p>
<p dir="auto">programmation: Francois Blais Montreal QC</p>
<p dir="auto">capture de trame pour la decouverte de commutateur (lldp)</p>
<h2>materiels</h2>
<p dir="auto">M5stack core  4meg prog   1.2 meg  ram<br />
ecran affichage avec un OLED  integer au bibli m5stack (esp32)   M5.LCD.println();<br />
3 bouton<br />
1 haut parleur</p>
<p dir="auto">module battery<br />
module lan_w5500   ethernet2.h   rj45</p>
<h2>bibliotheques</h2>
<p dir="auto">chemin de bibli shield w5500 lecture en mode raw   C:\Users\fblai\Documents\Arduino\libraries\Ethernet\src\utility</p>
<p dir="auto">C:\Users\fblai\Documents\Arduino\libraries</p>
<h1>problèmes  constatés</h1>
<p dir="auto">1-  bibliotherque doit etre celle fournie par m5stack dans la section module/w5500 sinon erreur manque var<br />
2-  pour utiliser le serveur test de m5stack dans  la section module/w5500 il faut prendre ladresse 192.168.0.177 pour ce conformer a la plage disponible sur mon routeur<br />
3-  il faut serrer les trois modules car probleme de connection physique  sinon led power clignote<br />
4-  il faut mettre dans le w5500.init(CS)  qui est CS=26 au lieu de celui par defaut qui est 10<br />
5-  utilisation des socket a partir de lobjet  w5500.execCmdSn(s,sock_open ou close  ou recv )</p>
<h1>utilisation de m5stack</h1>
<p dir="auto">bouton de power sur le coté<br />
peser une fois sur le power pour le demarrer ou le reinitialier<br />
peser 2 fois sur le power pour le fermer</p>
<p dir="auto">==================================================== */</p>
<p dir="auto">/* ====================================================<br />
bibli<br />
==================================================== */</p>
<p dir="auto">#include &lt;M5Stack.h&gt;</p>
<p dir="auto">//------------------- ethernet2  w5500  lan rj45</p>
<p dir="auto">#include &lt;SPI.h&gt;<br />
#include &lt;Ethernet2.h&gt;<br />
#include &lt;utility/w5500.h&gt;   // doit etre sous &lt;Ethernet2.h&gt;</p>
<p dir="auto">#define SCK 18          //   adaptation pour m5stack<br />
#define MISO 19<br />
#define MOSI 23<br />
#define CS 26</p>
<p dir="auto">// Enter a MAC address and IP address for your controller below.<br />
// The IP address will be dependent on your local network:   FB:AD:BE:EF:FE:FB    192.168.0.177<br />
byte mac[] = {<br />
0xFB, 0xAD, 0xBE, 0xEF, 0xFE, 0xFB<br />
};</p>
<p dir="auto">SOCKET s; //  RAW mode</p>
<p dir="auto">int rbuflen ;</p>
<p dir="auto">byte  trame[335];</p>
<p dir="auto">int NBR = 0;<br />
int position[12];</p>
<p dir="auto">/* ====================================================<br />
affichage<br />
==================================================== */</p>
<p dir="auto">String LCD_data[7];</p>
<p dir="auto">void presentation(String L1,String L2,String L3,String L4,String L5,String L6,String L7,String L8){<br />
M5.Lcd.clear();<br />
M5.Lcd.setCursor(70, 20, 4);<br />
M5.Lcd.println(L1);<br />
M5.Lcd.setCursor(70, 60, 4);<br />
M5.Lcd.println(L2);<br />
M5.Lcd.setCursor(70, 80, 4);<br />
M5.Lcd.println(L3);<br />
M5.Lcd.setCursor(70, 100, 4);<br />
M5.Lcd.println(L4);<br />
M5.Lcd.setCursor(70, 120, 4);<br />
M5.Lcd.println(L5);<br />
M5.Lcd.setCursor(70, 140, 4);<br />
M5.Lcd.println(L6);<br />
M5.Lcd.setCursor(70, 160, 4);<br />
M5.Lcd.println(L7);<br />
M5.Lcd.setCursor(70, 180, 4);<br />
M5.Lcd.println(L8);<br />
}</p>
<p dir="auto">/* ====================================================<br />
declaration de mes fonctions<br />
==================================================== */</p>
<p dir="auto">bool si_lldp();<br />
void lldp();<br />
String decoupe( unsigned int local  );<br />
int trouve( const byte rech[] );<br />
String decoupevlan( unsigned int local  );<br />
int* trouvetlv();<br />
String decompte;<br />
void matrame();<br />
String x2i(String monhexa);</p>
<p dir="auto">// ========================================================================================================<br />
// =============== fonctionne au debut du script seulement one shot =======================================<br />
// ========================================================================================================</p>
<p dir="auto">void setup()<br />
{<br />
Serial.begin(115200);</p>
<pre><code>M5.begin(true, false, true);
M5.Power.begin();
M5.Lcd.setTextFont(4);
M5.Lcd.setCursor(50, 100, 4);
</code></pre>
<p dir="auto">// ============ initialise lecran oled ===================</p>
<p dir="auto">presentation( "SWID-M5 v0.3 " ,    " "  ,"Capteur Ethernet", "" ,"Trame LLDP " ," "," ","F.Blais MTL 2020" );<br />
delay(5000);</p>
<p dir="auto">// ============ initialise ethernet en mode raw brodcast ===================</p>
<p dir="auto">SPI.begin(SCK, MISO, MOSI, -1);</p>
<p dir="auto">w5500.init(CS);<br />
w5500.writeSnMR(s, SnMR::MACRAW);<br />
w5500.execCmdSn(s, Sock_OPEN);<br />
}<br />
// =====================================================================================================<br />
// ==================== en boucle continue ==============================================================<br />
// =====================================================================================================<br />
void loop()<br />
{<br />
NBR++;</p>
<p dir="auto">// ===================== info sur la switch  =======================</p>
<p dir="auto">Serial.println(decompte);</p>
<p dir="auto">rbuflen = w5500.getRXReceivedSize(s);</p>
<pre><code>if(rbuflen&gt;0) {
if(rbuflen &gt; sizeof(trame))
rbuflen = sizeof(trame);
w5500.recv_data_processing(s, trame, rbuflen);
w5500.execCmdSn(s, Sock_RECV);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">decompte = "  b:" + String(NBR) + "   g:" +  String(rbuflen) ;</p>
<p dir="auto">if ( rbuflen &gt; 0 ) {<br />
if (si_lldp()) {<br />
lldp();<br />
presentation( "" , LCD_data[0],LCD_data[1] ,LCD_data[2] ,LCD_data[3] , LCD_data[4] ,LCD_data[5], LCD_data[6]);<br />
delay(30000);<br />
}<br />
}</p>
<p dir="auto">}<br />
//  ===============================================================================================<br />
//  ==================================  mes fonctions    ====================================<br />
//  ===============================================================================================</p>
<p dir="auto">void lldp(){</p>
<p dir="auto">int local=0;<br />
String partie;<br />
trouvetlv();</p>
<p dir="auto">//   description<br />
partie = decoupe(   position[5] ) ;<br />
LCD_data[1] =  partie.substring(1,14);<br />
LCD_data[2] =  partie.substring(15,partie.length() );</p>
<p dir="auto">// ==============</p>
<p dir="auto">// equivalent Unit/port<br />
LCD_data[4] = decoupe(position[4] ) ;<br />
LCD_data[4].trim();</p>
<p dir="auto">// ===============<br />
// equivalent 00-80-c2-01 signature de la ligne vlan   pos:187   0x0bfc = 3068<br />
byte vlan[]={0x00,0x80,0xc2,0x01};<br />
local = trouve(vlan);</p>
<p dir="auto">if (  local &lt; 330 )<br />
LCD_data[6] = "Vlan:"  + decoupevlan(local) ;<br />
else<br />
LCD_data[6] = "   pas Vlan"  ;</p>
<p dir="auto">}<br />
// =============================================<br />
bool si_lldp() {</p>
<p dir="auto">if(   trame[2]  == 1 &amp;&amp;  trame[3]  == 128 &amp;&amp;  trame[4]  == 194 &amp;&amp;  trame[7]  == 14 )       {<br />
matrame();<br />
return true;<br />
}<br />
else<br />
return false;<br />
}<br />
//===========================================================<br />
void matrame()<br />
{<br />
for(int x = 0 ; x&lt; 334 ; x++)<br />
{<br />
Serial.print(trame[x]);   Serial.print(" ");<br />
}<br />
Serial.println("");<br />
for(int x = 0 ; x&lt; 334 ; x++)<br />
{<br />
Serial.print(trame[x],HEX);<br />
}<br />
Serial.println("");<br />
}<br />
//  ========================================================<br />
//<br />
//  EXTRAIT UN MORCEAU EN HEXA ET LE RENVOI EN STRING</p>
<p dir="auto">String decoupe( unsigned int local  ) {<br />
unsigned int i;<br />
int grandeur = trame[local+1] ;<br />
String texte=" ";<br />
for ( i = ( local + 2 )   ; i &lt; (local + grandeur + 2)  ; i++  )<br />
texte +=   (char)trame[i] ;<br />
return texte;<br />
}<br />
//  ========================================================<br />
//<br />
//  EXTRAIT UN MORCEAU EN HEXA ET LE RENVOI EN STRING</p>
<p dir="auto">String decoupevlan( unsigned int local  ) {<br />
unsigned int i;<br />
int grandeur = trame[local-1] ;<br />
grandeur = grandeur - 4 ;</p>
<p dir="auto">String texte ;<br />
for ( i = (local+4)   ; i&lt; ( (local+4) + ( grandeur) )   ; i++  )<br />
texte += String(trame[i],HEX);<br />
texte = x2i(texte);<br />
texte.trim();<br />
return texte;<br />
}<br />
//  ========================================================<br />
//<br />
//  RECHERCHE UN MORCEAU SPECIFIQUE DANS LA TRAME<br />
//<br />
// =======================================================<br />
int trouve(const byte rech[] ) {<br />
unsigned int i = 0;<br />
for ( i = 0 ; i &lt; 330  ; i++ ) {<br />
if (trame[i] == rech[0])<br />
if( (trame[i+1] == rech[1]) and (trame[i+2] == rech[2]) and (trame[i+3] == rech[3]) )<br />
return i;<br />
}<br />
return 0;<br />
}<br />
// =================================================================<br />
// trouve les deplacements<br />
//<br />
int* trouvetlv(){<br />
int nbr;<br />
int pos = 16;       position[0]=0;   position[1]=16;</p>
<p dir="auto">for ( nbr = 2 ; nbr &lt; 9  ; nbr++ ) {</p>
<pre><code>position[nbr] =  ( (pos + 2) + trame[pos+1]   );
pos  = position[nbr];
</code></pre>
<p dir="auto">}<br />
return position ;<br />
}<br />
// ======================================================================<br />
String print_ip(const byte a[], unsigned int offset, unsigned int length) {<br />
String ip;<br />
for (unsigned int i = offset; i &lt; offset + length; i++) {<br />
//    if(i&gt;offset) Serial.print('.');<br />
//   Serial.print(a[i], DEC);<br />
if (i &gt; offset) ip = ip + '.';<br />
ip = ip + String (a[i]);<br />
}</p>
<p dir="auto">return ip;<br />
}<br />
// ======================================================================<br />
String print_mac(const byte a[], unsigned int offset, unsigned int length) {<br />
String Mac;</p>
<p dir="auto">LCD_data[1] = "";<br />
for (unsigned int i = offset; i &lt; offset + length; ++i) {</p>
<pre><code>if (i &gt; offset) {
  //  LCD_data[1] = LCD_data[1] + Mac + ':';
  Mac = Mac + ':';
}
if (a[i] &lt; 0x10) {
  Mac = Mac + '0';
  //    LCD_data[1] = LCD_data[1] + Mac + '0';
}
Mac = Mac + String (a[i], HEX);
</code></pre>
<p dir="auto">}<br />
LCD_data[1] = LCD_data[1]  + Mac;<br />
return Mac;<br />
}<br />
//  ====================================================<br />
//<br />
//  converti hexa vers dec en type string<br />
//<br />
//  ====================================================<br />
String x2i(String monhexa)<br />
{<br />
int x = 0; int nbr;<br />
for(nbr=0 ; nbr &lt; monhexa.length() ; nbr++) {</p>
<pre><code>if (monhexa[nbr] &gt;= '0' &amp;&amp; monhexa[nbr] &lt;= '9') {
  x *= 16;
  x += monhexa[nbr] - '0';
}
else if (monhexa[nbr] &gt;= 'A' &amp;&amp; monhexa[nbr] &lt;= 'F') {
  x *= 16;
  x += (monhexa[nbr] - 'A') + 10;
}
else if (monhexa[nbr] &gt;= 'a' &amp;&amp; monhexa[nbr] &lt;= 'f') {
  x *= 16;
  x += (monhexa[nbr] - 'a') + 10;
}
else break;
</code></pre>
<p dir="auto">}<br />
return String(x,DEC);<br />
}<br />
// ================= fin script =====================================================================================================<br />
// ================= fin script =====================================================================================================<br />
// ================= fin script =====================================================================================================</p>
]]></description><link>https://community.m5stack.com/post/11488</link><guid isPermaLink="true">https://community.m5stack.com/post/11488</guid><dc:creator><![CDATA[fblais]]></dc:creator><pubDate>Fri, 01 Jan 2021 12:40:32 GMT</pubDate></item><item><title><![CDATA[Reply to LAN Module: Reading RAW-packets on Sun, 02 Aug 2020 12:00:12 GMT]]></title><description><![CDATA[<p dir="auto">hi,</p>
<p dir="auto">i want to make a lldp sniffer with my m5stack core + batterie module and lan module</p>
<p dir="auto">is your research avancing and would you be willing to help a fellow m5stack-man ?</p>
]]></description><link>https://community.m5stack.com/post/9566</link><guid isPermaLink="true">https://community.m5stack.com/post/9566</guid><dc:creator><![CDATA[fblais]]></dc:creator><pubDate>Sun, 02 Aug 2020 12:00:12 GMT</pubDate></item><item><title><![CDATA[Reply to LAN Module: Reading RAW-packets on Sun, 12 Jul 2020 19:27:57 GMT]]></title><description><![CDATA[<p dir="auto">I got it!<br />
Code: <a href="https://github.com/njh/W5500MacRaw" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/njh/W5500MacRaw</a></p>
<p dir="auto">Some changes needed:</p>
<p dir="auto">replace "mr" with "mra"<br />
replace "MR" with "MRA". MR or mr is already in use from the esp-library</p>
<p dir="auto">CS-Pin:<br />
replace Wiznet5500 w5500; --&gt; Wiznet5500 w5500(26);</p>
<p dir="auto">Thank you for reading!<br />
Torsten</p>
]]></description><link>https://community.m5stack.com/post/9318</link><guid isPermaLink="true">https://community.m5stack.com/post/9318</guid><dc:creator><![CDATA[tnetwork]]></dc:creator><pubDate>Sun, 12 Jul 2020 19:27:57 GMT</pubDate></item></channel></rss>