gmuth / ipp-client-kotlin

A client implementation of the ipp protocol written in kotlin
MIT License
66 stars 9 forks source link

Epson L3250 failed to decode ipp response #6

Closed muhammadn closed 2 years ago

muhammadn commented 2 years ago

response output based in issueNo3.kt test file decoding_ipp_response.zip

Error trace

IppConfig                 INFO  userName: zaihan
IppConfig                 INFO  ippVersion: 1.1
IppConfig                 INFO  charset: utf-8
IppConfig                 INFO  naturalLanguage: en
IppConfig                 INFO  getPrinterAttributesOnInit: true
IssueNo3Kt                INFO  open ipp connection to ipps://192.168.1.7:631/ipp/print
HttpURLConnectionClient   DEBUG HttpURLConnectionClient created
IppPrinter                DEBUG create IppPrinter for ipps://192.168.1.7:631/ipp/print
IppOutputStream           DEBUG version = 1.1
IppOutputStream           DEBUG code = 11 (Get-Printer-Attributes)
IppOutputStream           DEBUG requestId = 1
IppOutputStream           DEBUG --- operation-attributes-tag ---
IppOutputStream           DEBUG attributes-charset (charset) = utf-8
IppOutputStream           DEBUG attributes-natural-language (naturalLanguage) = en
IppOutputStream           DEBUG printer-uri (uri) = ipps://192.168.1.7:631/ipp/print
IppOutputStream           DEBUG requesting-user-name (nameWithoutLanguage) = zaihan
IppOutputStream           DEBUG --- end-of-attributes-tag ---
IppMessage                DEBUG wrote 151 raw bytes
IppMessage                DEBUG consumed documentInputStream
HttpURLConnectionClient   TRACE Keep-Alive = [timeout=30]
HttpURLConnectionClient   TRACE null = [HTTP/1.1 200 OK]
HttpURLConnectionClient   TRACE Cache-Control = [no-cache]
HttpURLConnectionClient   TRACE Server = [Epson_IPP-Server/2.0.0]
HttpURLConnectionClient   TRACE Connection = [Keep-Alive]
HttpURLConnectionClient   TRACE Pragma = [no-cache]
HttpURLConnectionClient   TRACE Content-Length = [7452]
HttpURLConnectionClient   TRACE Content-Type = [application/ipp]
IppInputStream            DEBUG version = 1.1
IppInputStream            DEBUG code = 0 (successful-ok)
IppInputStream            DEBUG requestId = 1
IppInputStream            DEBUG --- operation-attributes-tag ---
IppInputStream            DEBUG attributes-charset (charset) = utf-8
IppInputStream            DEBUG attributes-natural-language (naturalLanguage) = en
IppInputStream            DEBUG --- printer-attributes-tag ---
IppInputStream            DEBUG copies-default (integer) = 1
IppInputStream            DEBUG copies-supported (rangeOfInteger) = 1-99
IppInputStream            DEBUG finishings-default (1setOf enum) = none
IppInputStream            DEBUG finishings-supported (1setOf enum) = none
IppInputStream            DEBUG sides-default (keyword) = one-sided
IppInputStream            DEBUG sides-supported (1setOf keyword) = one-sided
IppInputStream            DEBUG orientation-requested-default (enum) = portrait
IppInputStream            DEBUG orientation-requested-supported (1setOf enum) = portrait
IppInputStream            DEBUG media-default (keyword) = iso_a4_210x297mm
IppInputStream            DEBUG media-supported (1setOf keyword) = iso_a4_210x297mm
IppInputStream            DEBUG  (keyword) = na_index-4x6_4x6in
IppInputStream            DEBUG  (keyword) = na_5x7_5x7in
IppInputStream            DEBUG  (keyword) = na_govt-letter_8x10in
IppInputStream            DEBUG  (keyword) = om_hivision_101.6x180.6mm
IppInputStream            DEBUG  (keyword) = iso_a5_148x210mm
IppInputStream            DEBUG  (keyword) = iso_a6_105x148mm
IppInputStream            DEBUG  (keyword) = na_legal_8.5x14in
IppInputStream            DEBUG  (keyword) = na_letter_8.5x11in
IppInputStream            DEBUG  (keyword) = jis_b5_182x257mm
IppInputStream            DEBUG  (keyword) = jis_b6_128x182mm
IppInputStream            DEBUG  (keyword) = oe_photo-l_3.5x5in
IppInputStream            DEBUG  (keyword) = jpn_hagaki_100x148mm
IppInputStream            DEBUG  (keyword) = na_number-10_4.125x9.5in
IppInputStream            DEBUG  (keyword) = iso_c6_114x162mm
IppInputStream            DEBUG  (keyword) = iso_dl_110x220mm
IppInputStream            DEBUG  (keyword) = na_index-5x8_5x8in
IppInputStream            DEBUG  (keyword) = na_foolscap_8.5x13in
IppInputStream            DEBUG  (keyword) = om_16k_195x270mm
IppInputStream            DEBUG  (keyword) = om_indian-legal_215x345mm
IppInputStream            DEBUG  (keyword) = custom_min_54x86mm
IppInputStream            DEBUG  (keyword) = custom_max_215.9x1200mm
IppInputStream            DEBUG printer-resolution-default (resolution) = 360 dpi
IppInputStream            DEBUG printer-resolution-supported (1setOf resolution) = 360 dpi
IppInputStream            DEBUG  (resolution) = 1440x720 dpi
IppInputStream            DEBUG print-quality-default (enum) = normal
IppInputStream            DEBUG print-quality-supported (1setOf enum) = normal
IppInputStream            DEBUG  (enum) = 5
IppInputStream            DEBUG output-bin-default (keyword) = face-up
IppInputStream            DEBUG output-bin-supported (1setOf keyword) = face-up
IppInputStream            DEBUG media-col-supported (1setOf keyword) = media-size
IppInputStream            DEBUG  (keyword) = media-top-margin
IppInputStream            DEBUG  (keyword) = media-left-margin
IppInputStream            DEBUG  (keyword) = media-right-margin
IppInputStream            DEBUG  (keyword) = media-bottom-margin
IppInputStream            DEBUG  (keyword) = media-type
IppInputStream            DEBUG  (keyword) = media-source
IppInputStream            DEBUG media-col-default (collection) = {media-size={x-dimension=21000 y-dimension=29700} media-top-margin=300 media-left-margin=300 media-right-margin=300 media-bottom-margin=300 media-type=stationery media-source=main}
IppInputStream            DEBUG print-color-mode-default (keyword) = auto
IppInputStream            DEBUG print-color-mode-supported (1setOf keyword) = color
IppInputStream            DEBUG  (keyword) = monochrome
IppInputStream            DEBUG  (keyword) = auto-monochrome
IppInputStream            DEBUG  (keyword) = process-monochrome
IppInputStream            DEBUG  (keyword) = auto
IppInputStream            DEBUG print-content-optimize-default (keyword) = auto
IppInputStream            DEBUG print-content-optimize-supported (1setOf keyword) = auto
IppInputStream            DEBUG print-scaling-default (keyword) = auto
IppInputStream            DEBUG print-scaling-supported (1setOf keyword) = auto
IppInputStream            DEBUG  (keyword) = auto-fit
IppInputStream            DEBUG  (keyword) = fill
IppInputStream            DEBUG  (keyword) = fit
IppInputStream            DEBUG  (keyword) = none
IppInputStream            DEBUG media-size-supported (1setOf collection) = {x-dimension=21000 y-dimension=29700}
IppInputStream            DEBUG  (collection) = {x-dimension=10160 y-dimension=15240}
IppInputStream            DEBUG  (collection) = {x-dimension=12700 y-dimension=17780}
IppInputStream            DEBUG  (collection) = {x-dimension=20320 y-dimension=25400}
IppInputStream            DEBUG  (collection) = {x-dimension=10160 y-dimension=18060}
IppInputStream            DEBUG  (collection) = {x-dimension=14800 y-dimension=21000}
IppInputStream            DEBUG  (collection) = {x-dimension=10500 y-dimension=14800}
IppInputStream            DEBUG  (collection) = {x-dimension=21590 y-dimension=35560}
IppInputStream            DEBUG  (collection) = {x-dimension=21590 y-dimension=27940}
IppInputStream            DEBUG  (collection) = {x-dimension=18200 y-dimension=25700}
IppInputStream            DEBUG  (collection) = {x-dimension=12800 y-dimension=18200}
IppInputStream            DEBUG  (collection) = {x-dimension=8890 y-dimension=12700}
IppInputStream            DEBUG  (collection) = {x-dimension=10000 y-dimension=14800}
IppInputStream            DEBUG  (collection) = {x-dimension=10477 y-dimension=24130}
IppInputStream            DEBUG  (collection) = {x-dimension=11400 y-dimension=16200}
IppInputStream            DEBUG  (collection) = {x-dimension=11000 y-dimension=22000}
IppInputStream            DEBUG  (collection) = {x-dimension=12700 y-dimension=20320}
IppInputStream            DEBUG  (collection) = {x-dimension=21590 y-dimension=33020}
IppInputStream            DEBUG  (collection) = {x-dimension=19500 y-dimension=27000}
IppInputStream            DEBUG  (collection) = {x-dimension=21500 y-dimension=34500}
IppInputStream            DEBUG  (collection) = {x-dimension=5400..21590 y-dimension=8600..120000}
IppInputStream            DEBUG media-type-supported (1setOf keyword) = stationery
IppInputStream            DEBUG  (keyword) = photographic-high-gloss
IppInputStream            DEBUG  (keyword) = photographic
IppInputStream            DEBUG  (keyword) = photographic-semi-gloss
IppInputStream            DEBUG  (keyword) = photographic-glossy
IppInputStream            DEBUG  (keyword) = photographic-matte
IppInputStream            DEBUG  (keyword) = stationery-coated
IppInputStream            DEBUG  (keyword) = envelope
IppInputStream            DEBUG media-source-supported (1setOf keyword) = main
IppInputStream            DEBUG media-top-margin-supported (1setOf integer) = 0
IppInputStream            DEBUG  (integer) = 300
IppInputStream            DEBUG media-left-margin-supported (1setOf integer) = 0
IppInputStream            DEBUG  (integer) = 300
IppInputStream            DEBUG media-right-margin-supported (1setOf integer) = 0
IppInputStream            DEBUG  (integer) = 300
IppInputStream            DEBUG media-bottom-margin-supported (1setOf integer) = 0
IppInputStream            DEBUG  (integer) = 300
IppInputStream            DEBUG charset-configured (charset) = utf-8
IppInputStream            DEBUG charset-supported (1setOf charset) = utf-8
IppInputStream            DEBUG color-supported (boolean) = true
IppInputStream            DEBUG compression-supported (1setOf keyword) = none
IppInputStream            DEBUG  (keyword) = gzip
IppInputStream            DEBUG document-format-default (mimeMediaType) = application/octet-stream
IppInputStream            DEBUG document-format-supported (1setOf mimeMediaType) = application/octet-stream
IppInputStream            DEBUG  (mimeMediaType) = image/pwg-raster
IppInputStream            DEBUG  (mimeMediaType) = application/vnd.epson.escpr
IppInputStream            DEBUG generated-natural-language-supported (1setOf naturalLanguage) = en
IppInputStream            DEBUG ipp-versions-supported (1setOf keyword) = 1.0
IppInputStream            DEBUG  (keyword) = 1.1
IppInputStream            DEBUG  (keyword) = 2.0
IppInputStream            DEBUG natural-language-configured (naturalLanguage) = en
IppInputStream            DEBUG operations-supported (1setOf enum) = Print-Job
IppInputStream            DEBUG  (enum) = 4
IppInputStream            DEBUG  (enum) = 5
IppInputStream            DEBUG  (enum) = 6
IppInputStream            DEBUG  (enum) = 8
IppInputStream            DEBUG  (enum) = 9
IppInputStream            DEBUG  (enum) = 10
IppInputStream            DEBUG  (enum) = 11
IppInputStream            DEBUG  (enum) = 59
IppInputStream            DEBUG  (enum) = 60
IppInputStream            DEBUG pages-per-minute (integer) = 4
IppInputStream            DEBUG pages-per-minute-color (integer) = 9
IppInputStream            DEBUG pdl-override-supported (keyword) = attempted
IppInputStream            DEBUG printer-alert (1setOf octetString) = code=other
IppInputStream            DEBUG printer-alert-description (1setOf textWithoutLanguage) = idle
IppInputStream            DEBUG printer-device-id (textWithoutLanguage) = MFG:EPSON;CMD:ESCPL2,BDC,D4,D4PX,ESCPR1,END4,GENEP,PWGRaster;MDL:L3250 Series;CLS:PRINTER;DES:EPSON L3250 Series;CID:EpsonRGB;FID:FXN,DPN,WFA,ETN,AFN,DAN,WRA;RID:50;DDS:022500;ELG:1163;
IppInputStream            DEBUG printer-info (textWithoutLanguage) = EPSON L3250 Series
IppInputStream            DEBUG printer-is-accepting-jobs (boolean) = true
IppInputStream            DEBUG printer-location (textWithoutLanguage) = 
IppInputStream            DEBUG printer-make-and-model (textWithoutLanguage) = EPSON L3250 Series
IppInputStream            DEBUG printer-more-info (uri) = http://192.168.1.7:80/PRESENTATION/
IppInputStream            DEBUG printer-name (nameWithoutLanguage) = ipp/print
IppInputStream            DEBUG printer-state (enum) = idle
IppInputStream            DEBUG printer-state-reasons (1setOf keyword) = none
IppInputStream            DEBUG printer-up-time (integer) = 24070
IppInputStream            DEBUG printer-uri-supported (1setOf uri) = ipps://192.168.1.7:631/ipp/print
IppInputStream            DEBUG  (uri) = ipp://192.168.1.7:631/ipp/print
IppInputStream            DEBUG queued-job-count (integer) = 0
IppInputStream            DEBUG uri-security-supported (1setOf keyword) = tls
IppInputStream            DEBUG  (keyword) = none
IppInputStream            DEBUG uri-authentication-supported (1setOf keyword) = none
IppInputStream            DEBUG  (keyword) = none
IppInputStream            DEBUG printer-geo-location (unknown) = no-value
IppInputStream            DEBUG identify-actions-default (1setOf keyword) = flash
IppInputStream            DEBUG identify-actions-supported (1setOf keyword) = flash
IppInputStream            DEBUG jpeg-k-octets-supported (rangeOfInteger) = 0-16384
IppInputStream            DEBUG jpeg-x-dimension-supported (rangeOfInteger) = 0-10200
IppInputStream            DEBUG jpeg-y-dimension-supported (rangeOfInteger) = 1-10200
IppInputStream            DEBUG pdf-versions-supported (1setOf keyword) = none
IppInputStream            DEBUG urf-supported (keyword) = 
IppInputStream            DEBUG job-creation-attributes-supported (1setOf keyword) = copies
IppInputStream            DEBUG  (keyword) = finishings
IppInputStream            DEBUG  (keyword) = ipp-attribute-fidelity
IppInputStream            DEBUG  (keyword) = job-name
IppInputStream            DEBUG  (keyword) = media
IppInputStream            DEBUG  (keyword) = media-col
IppInputStream            DEBUG  (keyword) = orientation-requested
IppInputStream            DEBUG  (keyword) = output-bin
IppInputStream            DEBUG  (keyword) = print-quality
IppInputStream            DEBUG  (keyword) = printer-resolution
IppInputStream            DEBUG  (keyword) = sides
IppInputStream            DEBUG  (keyword) = print-color-mode
IppInputStream            DEBUG  (keyword) = print-content-optimize
IppInputStream            DEBUG  (keyword) = print-scaling
IppInputStream            DEBUG  (keyword) = job-mandatory-attributes
IppInputStream            DEBUG marker-names (nameWithoutLanguage) = 
IppInputStream            DEBUG marker-colors (nameWithoutLanguage) = 
IppInputStream            DEBUG marker-types (keyword) = 
IppInputStream            WARN  0 unparsed bytes
IppMessage                DEBUG read 7452 raw bytes
IppMessage                INFO  saved: /var/folders/1q/70cvcdv51c9dz1zh2rblc5d40000gn/T/decoding_ipp_response_1_failed.request18252367558343606700.tmp
IppMessage                INFO  saved: /var/folders/1q/70cvcdv51c9dz1zh2rblc5d40000gn/T/decoding_ipp_response_1_failed.response7224328624350043788.tmp
IssueNo3Kt                ERROR failed to connect to ipps://192.168.1.7:631/ipp/print
de.gmuth.ipp.client.IppExchangeException: failed to decode ipp response
    at de.gmuth.ipp.client.IppClient.decodeIppResponse(IppClient.kt:135)
    at de.gmuth.ipp.client.IppClient.exchange(IppClient.kt:84)
    at de.gmuth.ipp.client.IppPrinter.exchange(IppPrinter.kt:384)
    at de.gmuth.ipp.client.IppPrinter.getPrinterAttributes(IppPrinter.kt:198)
    at de.gmuth.ipp.client.IppPrinter.getPrinterAttributes$default(IppPrinter.kt:197)
    at de.gmuth.ipp.client.IppPrinter.updateAllAttributes(IppPrinter.kt:201)
    at de.gmuth.ipp.client.IppPrinter.<init>(IppPrinter.kt:33)
    at de.gmuth.ipp.client.IppPrinter.<init>(IppPrinter.kt:20)
    at de.gmuth.ipp.client.IssueNo3Kt.main(issueNo3.kt:30)
    at de.gmuth.ipp.client.IssueNo3Kt.main(issueNo3.kt)
Caused by: de.gmuth.ipp.core.IppException: failed to read attribute value of 'marker-low-levels' (integer)
    at de.gmuth.ipp.core.IppInputStream.readAttribute$ipp_client_kotlin(IppInputStream.kt:76)
    at de.gmuth.ipp.core.IppInputStream.readMessage(IppInputStream.kt:47)
    at de.gmuth.ipp.core.IppMessage.read(IppMessage.kt:97)
    at de.gmuth.ipp.client.IppClient.decodeIppResponse(IppClient.kt:133)
    ... 9 more
Caused by: de.gmuth.ipp.core.IppException: expected value length of 4 bytes but found 0
    at de.gmuth.ipp.core.IppInputStream.readExpectedValueLength$ipp_client_kotlin(IppInputStream.kt:203)
    at de.gmuth.ipp.core.IppInputStream.readAttributeValue$ipp_client_kotlin(IppInputStream.kt:93)
    at de.gmuth.ipp.core.IppInputStream.readAttribute$ipp_client_kotlin(IppInputStream.kt:73)
    ... 12 more

Process finished with exit code 0
gmuth commented 2 years ago

This indicates that the printer does not respond with valid ipp. I assume this error is reproducable. I've updated the code for better logging and error analysis. The attached file looks incomplete. Some times value encodings are incorrect and one can guess or see what is missing. In such cases usually more bytes follow after end incorrect encoding - that's where I could try to implement a workaround.

Anyway, please update, build and try my latest source code. You should get a file getPrinterAttributesFailed.bin which I kindly ask you to post here again including the new logs. I've added an operation that saves pure http content without trying to parse the ipp message.

muhammadn commented 2 years ago

@gmuth Will test the latest source code. Sorry for taking time as i was out of town.

I've also called Epson today and when i was troubleshooting for a macOS machine to print out (using generic postscript driver), it comes out garbage, the same thing happens when i make this library be less strict with ipp response.

Epson clarified that i would need their driver.

gmuth commented 2 years ago

@muhammadn, what's the result/output concerning the lastest updates I have committed and pushed? You can always test with ipptool as well - e.g. https://github.com/apple/cups/blob/master/examples/get-printer-attributes.test.

Looking at the specs of the printer I can't see what output formats are supported for printing. Somewhere else they list: ESC/P-R, ESC/P Raster

From you logs I can see that the printer lists: document-format-supported (1setOf mimeMediaType) = [application/octet-stream, image/pwg-raster, application/vnd.epson.escpr]

IPP can only be used to transmit printable documents to the printer in a format it supports.

muhammadn commented 2 years ago

@gmuth I forgot. I did ipptool before.

Here is the result for ipptool:

─$ ipptool -tv ipp://192.168.1.7/ipp/printer get-printer-attributes.test
"/usr/share/cups/ipptool/get-printer-attributes.test":
    Get-Printer-Attributes:
        attributes-charset (charset) = utf-8
        attributes-natural-language (naturalLanguage) = en
        printer-uri (uri) = ipp://192.168.1.7:631/ipp/printer
    Get printer attributes using Get-Printer-Attributes                  [FAIL]
        RECEIVED: 0 bytes in response
        status-code = server-error-internal-error (No request sent.)
        IPP request failed with status server-error-internal-error (No request sent.)

ipptool doesn't show much information. I'm extracting the .bin file at the moment, i've hacked parts of your code to allow to save the file on android (since android has strict permissions) and i am extracting that .bin out.

Do note that i tested on a photocopier which is a Ricoh bizHub and prints perfectly, ipptool for the Ricoh bizHub also successfully provided me with printer attributes. I used your code for a flutter app (which uses a bridge to call your kotlin code)

Just this epson L3250 is giving problems. If this printer is giving problems then i'll try to find some compatible ones out there. But i'm unsure which could work though.

muhammadn commented 2 years ago

getPrinterAttributesFailed.bin.zip

Here is the file. Github doesn't allow .bin extension so i had to zip it.

gmuth commented 2 years ago

If the printer does not meet your requirements you should look into the specs when buying a new one. I prefer AirPrint printers because they implement IPP and more likely support PDF natively. Unfortunately manufacturers hardly document the supported pdls or document formats. Even via IPP sometimes they don't announce a full list of formats.

muhammadn commented 2 years ago

@gmuth Yeah, we got that printer for free (new) and now it's either i hack the code (is it because they never announce the pdls?) to ignore the pdl and continue printing.

I did see the pdl information in the bin file, most notably printer-device-id

printer-device-id��MFG:EPSON;CMD:ESCPL2,BDC,D4,D4PX,ESCPR1,END4,GENEP,PWGRaster

Printer does not seem to support PDF so i would have to use PWGRaster and one of the way to do with a library is to use https://github.com/HPInc/jipp to convert pdf to PWGRaster

Only problem is i would have to write java code.

gmuth commented 2 years ago

Thank you for the extra bin-file update. The printer does not send a complete valid response. Without having the printer available it's difficult to look for workarounds. The idea is to exclude the invalid marker attributes from the response by not asking for all printer attributes.

I have enhanced the initialisation process. You can now limit the printer attributes requested. For details look into RFC 8011 section 4.2.5.

val ippConf = IppConfig().apply {
    requestedAttributesOnInit = IppPrinter.printerClassAttributes
}

Or you can disable get-printer-attributes completely:

val ippConf = IppConfig().apply {
    getPrinterAttributesOnInit = false
}

Maybe you can fetch the job-template attributes without issues:

IppPrinter(uri, ippConfig = ippConf).apply {
    updateAttributes("job-template")
}

Please check if this solves the original issue "failed to decode ipp response"

gmuth commented 2 years ago

Printers sometimes respond with invalid ipp responses. Disabling GetPrinterAttributesOnInit solves this issue. Generally the library should work without the printer attributes though I've not tested this special case a lot.